firebase - Firestore 中的复合查询 - “order by”和“where”中的不同字段
问题描述
这可以在 Firebase Firestore 中使用吗?
var result = await firestoreInstance
.collection('messages')
.where('place', whereIn: ["value1","value2","value3","value4","value5","value6","value7","value8","value9"])
.orderBy('dateAdded')
.startAfterDocument(lastDocument)
.limit(documentLimit)
.getDocuments();
我的意思是,我想根据一个字段('place')上的 IN 条件过滤数据,然后根据另一个字段('dateAdded')对其进行分页。
它会在“place”和“dateAdded”字段上使用复合索引吗?我 Firestore 允许它,它可以在 Flutter SDK 中工作吗?
解决方案
应该可以正常工作 - 我已经在我的代码中执行了类似的操作。我通过尝试发现的一件事 - 使用“EndBeforeDocument”调用进行分页似乎需要反转orderBy,因此它需要设置多个复合索引。为您创建这些索引的页面链接将在 .get() 调用的“错误”中返回(因此请适当设置回调以捕获此问题)。
所以道格通常是对的,顺便说一句,不尝试(和/或搜索 StackOverflow)就提出问题的不礼貌 - 你很幸运,因为我刚刚为我的应用程序的库编写了自己的分页界面。虽然我打算尽快将接口作为 NPM 包发布,但它可能对您没有帮助 - 我在 React 下使用 Web API (javascript)。
推荐阅读
- javascript - 我无法在服务器端访问 socket.io?
- r - 使用选择表达式中列名的变量对 data.frame 进行子集
- javascript - 验证动态输入字段 Jquery
- symfony - Symfony 命令调用其他命令并等待确认
- java - 基于 ConcurrentSessionControllerImpl 的旧代码如何从 Spring Security 2.0 迁移到 3.0?
- node.js - 无法在弹性搜索中编写文档
- windows - 按数字顺序循环文件(如在 Windows 资源管理器上)
- angular - 如何将我的 Typescript 中的 Id 传递给解析器?
- excel - 在编辑栏中显示长日期格式
- html - Angular 应用程序 - 放置脚本标签的位置