Firestore queryBuilder中的多个where查询 [英] multiple where query in firestore queryBuilder

查看:43
本文介绍了Firestore queryBuilder中的多个where查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天才注意到,每当我要查询数据库时,都会收到一个错误,这对我来说实际上没有任何意义,并且查询只是停止工作.几周前就很好了.

I just noticed today that whenever I want to query a database I get an error which doesn't really make a sense to me and querying just stop working. It worked just fine few weeks ago.

无效的查询.不等式(小于,lessThanOrEqual,GreaterThan或GreaterThanOrEqual)必须位于同一领域.但是您在'value1'和'value2'上有不等式过滤器)

Invalid Query. All where filters with an inequality (lessThan, lessThanOrEqual, greaterThan, or greaterThanOrEqual) must be on the same field. But you have inequality filters on 'value1' and 'value2')

  Stream<List<MyModel>> myStream(
      {MyFilter filter, String category}) {
    return _service.collectionsStream(
        path: APIPath.tools(cid, category),
        queryBuilder: filter != null
            ? (query) => query
                .where('value1', isGreaterThan: filter.minValue1)
                .where('value1', isLessThan: filter.maxValue1)
                .where('value2', isLessThan: filter.maxValue2)
                .where('value2', isGreaterThan: filter.minValue2)
            : null,
        builder: (data, documentID) => MyModel.fromMap(data, documentID),
        sort: (lhs, rhs) => lhs.value1.compareTo(rhs.value1));
  }

我做错什么了吗?该错误是什么意思,为什么我上次没有得到它?

Am I doing something wrong? What does that error means and why I didn't get it last time?

推荐答案

Firestore查询只能在服务器上包含关系条件(> < 等)单一领域.从查询限制:

A Firestore query can only contain relational conditions (>, <, etc) on a single field. From the documentation on query limitations:

不支持在不同字段上具有范围过滤器的查询.

Queries with range filters on different fields are not supported.

因此,您必须选择要Firestore在其上执行范围过滤的字段.然后,您必须在应用程序代码中执行其他操作.

So you'll have to choose which field you want Firestore to perform a range filter on. You'll then have to do the others in your application code.

要了解有关为何存在此限制的更多信息,并在Firestore的限制范围内实施用例,我强烈建议您观看视频系列

To learn more about why this limit exists, and on working within Firestore's limitations to implement use-cases, I highly recommend checking out the video series Getting to know Cloud Firestore.

这篇关于Firestore queryBuilder中的多个where查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆