我在firestore查询中尝试实现逻辑OR运算符.
db.collection('users').where('company_id', '==', companyId)
.where('role', '==', 'Maker')
.where('role', '==', 'Checker')
.where('role', '==', 'Approver')
.get().then(function(adminsSnapshot){
//Some processing on dataSnapshot
})
Run Code Online (Sandbox Code Playgroud)
但这不是实施OR的正确方法.
我希望所有用户都拥有"Maker,Checker或Approver"角色.
我如何在firestore查询中实现OR?Doc中没有任何内容.
当我在我的 flutter 应用程序中使用 cloud firestore 时,发生了奇怪的异常。
已编辑
这是我的代码:
Stream<List<Product>> productsStream(int id) async* {
final k = _db
.collection('products')
.where('category_id', isEqualTo: id)
.where('stock', isGreaterThanOrEqualTo: 1)
.orderBy('order')
.snapshots();
yield* k.map((event) => event.docs
.map((e) => Product.fromJson(
e.data(),
))
.toList());
Run Code Online (Sandbox Code Playgroud)
在这里,我想要实现的是检查产品是否有库存,然后order在我的products收藏中按字段升序订购产品。
但我收到这个奇怪的错误:
例外:'package:cloud_firestore/src/query.dart':断言失败:第 421 行 pos 16:'field == orders[0][0]':初始 orderBy() 字段 '[[FieldPath([order]) , false]][0][0]' 必须与调用不等式运算符时的 where() 字段参数 'FieldPath([stock])' 相同。
什么可能是解决方案?