我找不到如何在Firestore Collection返回的Flutter Stream Builder中使用多个where子句的文档或示例。
以下查询可以正常工作
Firestore
.instance
.collection (collectionName)
.where ("index", arrayContains: search)
.orderBy ('date', descending: true )
.snapshots()但如果添加额外的where子句,则返回零
Firestore
.instance
.collection (collectionName)
.where ("index", arrayContains: search)
.where ('allowed_roles', arrayContains: GlobalVars.userRole.toString() )
.orderBy ('date', descending: true )
.snapshots() Firebase文档中的复合查询示例看起来与上面的非常相似,但是缺少Flutter或Dart示例。
编辑:我也尝试过查询构建模式作为变通方法,但它也不起作用。Flutter真的不想多次使用arrayContains子句。
CollectionReference collectionRef = Firestore.instance.collection (collectionName);
Query p = collectionRef.where ('allowed_roles', arrayContains: "3");
Query q = p.where ('index', arrayContains: "Dan");
Stream s = q.snapshots(); 我在这里缺少的是程序员应该使用什么解决方案来解决这个问题,逻辑AND是一个非常基本的等式,坚持这个特性是不寻常的。
发布于 2020-05-21 03:42:02
一个查询中不能有两个arrayContains筛选器:
.where ("index", arrayContains: search)
.where ('allowed_roles', arrayContains: GlobalVars.userRole.toString() )根据documentation的说法,一次只支持一个arrayContains。这是Firestore的一个限制,不能更改。查询肯定会生成错误-您应该添加代码来检查错误,而不是盲目地假设它成功了。
发布于 2020-05-21 04:19:47
正如在评论中提到的,Firebase不接受超过一个arrayContains子句。
对于我的情况,唯一的解决方案是在我的活动中为allow_roles数组挂接一个条件语句:
if( document['allowed_roles'].contains( GlobalVars.userRole ))https://stackoverflow.com/questions/61916346
复制相似问题