Firestore查询文档字段

huangapple go评论50阅读模式
英文:

Firestore OR querey for document fields

问题

有没有办法查询一个文档,以便任何字段等于某个值?

例如:

名为 chats 的文档集合。每个文档都有两个字段 - user1user2。我可以获取所有其中 user1user2 等于2的文档吗?

where('field', 'in', ['value1', 'value2']) 对此不起作用,因为它只能检查一个字段与多个值的情况。对吗?

英文:

Is there any way to query a document so that any field is equal to some value?

eg:

collection of documents named chats. Each document has two fields - user1 and user2. Can I get all the documents where user1 or user2 is 2?

where('field', 'in', ['value1', 'value2']) won't work for this because that can only check one field against multiple values. right?

答案1

得分: 1

Firestore不支持OR查询: 在Cloud Firestore中执行简单和复合查询

但是,您可以获取所有chatsuser1 === 2的文档,然后再获取所有user2 === 2的文档,并将结果连接在一起。

let combinedChatArray = chatOfUser1Array.concat(chatOfUser2Array);
英文:

Firestore does not support OR queries: Perform simple and compound queries in Cloud Firestore

However you can fetch all documents in chats with user1 === 2 and a second fetch with all documents with user2 === 2 and concat the results

let combinedChatArray = chatOfUser1Array.concat(chatOfUser2Array);

huangapple
  • 本文由 发表于 2023年2月23日 20:00:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544538.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定