在 Firestore 查询中实施 OR - Firebase Firestore [英] Implementing OR in firestore query - Firebase firestore

查看:31
本文介绍了在 Firestore 查询中实施 OR - Firebase Firestore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Firestore 查询中实现逻辑 OR 运算符.

I am trying implement logical OR operator in firestore query.

db.collection('users').where('company_id', '==', companyId)
                          .where('role', '==', 'Maker')
                          .where('role', '==', 'Checker')
                          .where('role', '==', 'Approver')
                          .get().then(function(adminsSnapshot){


             //Some processing on dataSnapshot
})

但这不是实现 OR 的正确方式.

But this is not the right way to implement OR.

我希望所有用户都具有制作者、检查者或审批者"角色.

I want all users with roles of 'Maker, Checker or Approver'.

我将如何在 Firestore 查询中实现 OR?文档中没有任何内容.

How would i implement OR in firestore query ? There's nothing in Doc.

推荐答案

编辑(2019 年 11 月)Cloud Firestore 现在支持IN"查询(公告) 允许您执行一种 OR 查询,以查找在同一字段中具有几个值之一的文档.

Edit (November 2019) Cloud Firestore now supports "IN" queries (announcement) which allows you to do a type of OR queries that look for documents with one of a few values on the same field.

例如上面的查询:

db.collection('users')
  .where('company_id', '==', companyId)
  .where('role', 'in', ['Maker', 'Checker', 'Approver']);


原答案

Cloud Firestore 中没有OR"查询.如果您想在单个查询中实现此目的,您将需要一个字段,例如 maker_or_checker_or_approver: true.

There is no "OR" query in Cloud Firestore. If you want to achieve this in a single query you will need a single field like maker_or_checker_or_approver: true.

当然,您始终可以执行三个查询并在客户端上加入它们.

Of course you can always do three queries and join them on the client.

这篇关于在 Firestore 查询中实施 OR - Firebase Firestore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆