且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在firebase中聚合查询

更新时间:2023-02-06 20:59:01

Cloud Firestore 不支持原生聚合查询.但是,您可以使用客户端事务或云函数来轻松维护聚合关于您的数据的信息.

Cloud Firestore does not support native aggregation queries. However, you can use client-side transactions or Cloud Functions to easily maintain aggregate information about your data.

Cloud Firestore 提供强大的查询功能,用于指定您需要哪些文档想要从集合或集合组中检索.

Cloud Firestore provides powerful query functionality for specifying which documents you want to retrieve from a collection or collection group.

您还可以链接多个 where() 方法来创建更具体的查询(逻辑与).但是,要将相等运算符 (==) 与范围或数组包含子句(<、<=、>、>= 或数组包含

You can also chain multiple where() methods to create more specific queries (logical AND). However, to combine the equality operator (==) with a range or array-contains clause (<, <=, >, >=, or array-contains

Cloud Firestore 不支持以下类型的查询:一个>

  • 对不同字段使用范围过滤器的查询,如上一节所述.
  • 逻辑 OR 查询.在这种情况下,您应该为每个 OR 条件创建一个单独的查询,并在您的应用中合并查询结果.
  • 带有 != 子句的查询.在这种情况下,您应该将查询拆分为大于查询和小于查询.例如,虽然不支持查询子句 where("age", "!=", "30"),但是可以通过组合两个查询来得到相同的结果集,一个带有子句 where("age", "<", "30") 和一个带有 where("age", ">", 30).