英文:
Firestore OR querey for document fields
问题
有没有办法查询一个文档,以便任何字段等于某个值?
例如:
名为 chats 的文档集合。每个文档都有两个字段 - user1 和 user2。我可以获取所有其中 user1 或 user2 等于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中执行简单和复合查询
但是,您可以获取所有chats中user1 === 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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论