Firebase Flatter Firestore:在同一查询中使用whereNotIn和arrayContains解析查询参数时出错
我的问题是:Firebase Flatter Firestore:在同一查询中使用whereNotIn和arrayContains解析查询参数时出错,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我的问题是: snapshot = await FirebaseFirestore.instance .collection('dialogs') .where('active', isEqualTo: true) .where('users', arrayContains: globals.user.userId) .where('readers', whereNotIn: [globals.user.userId
snapshot = await FirebaseFirestore.instance
.collection('dialogs')
.where('active', isEqualTo: true)
.where('users', arrayContains: globals.user.userId)
.where('readers', whereNotIn: [globals.user.userId])
.orderBy('priority')
.limit(1)
.get();
我得到了上述例外情况:
未处理的异常:[cloud\u firestore/unknown]分析查询参数时出错,有关详细信息,请参阅本机日志
我在官方网站上找到了一些注释:
- 每个查询最多可以使用一个in、
,或者not in
子句。不能在同一查询中组合这些运算符数组包含任何
- 不能将不在与不等于合并!=李>
- 如果我只删除
行,一切都很好whereNotIn
- 如果我只删除
行,一切都很好arrayContains
数组包含的
不能与不在
中位于同一查询中
结论
如果遇到查询解析异常。获取问题相关信息的最新、最快捷的方法是查看您的日志聊天。Firestore限制 Firebase firestore不允许您在单个查询中使用whereNotIn和arrayContains。 解决方案 拆分查询,首先按
snapshot = await FirebaseFirestore.instance
.collection('dialogs')
.where('active', isEqualTo: true)
.where('users', arrayContains: globals.user.userId)
//.where('readers', whereNotIn: [globals.user.userId]) <-- remove this
.orderBy('priority')
.limit(1)
.get();
snapshot=wait FirebaseFirestore.instance
.collection('对话框')
.where('active',isEqualTo:true)
.where('users',arrayContains:globals.user.userId)
//.where('readers',whereNotIn:[globals.user.userId])您是否为用户
和读者
字段创建了索引?嘿@Simon谢谢您的帮助。在获取创建索引的链接之前,我得到了一个异常。所以它没有索引。我已经向firebase支持团队报告了这个问题。Hey@M.AQIB感谢您的回复。我正面临Firestore的成本问题。由于Firestore对您每次读取都收取费用,因此在大范围内会变得非常昂贵。当然,您可以从一个集合中读取所有文档,然后在客户端对它们进行过滤,但这没有抓住要点(降低成本!)。但是,我认为你的回答会帮助别人,所以你得到我的赏金,享受吧!:)谢谢,我已经为未来的读者更新了答案!