Firebase获取数据比较两个字段 [英] Firebase get data compare two fields
问题描述
我正在尝试获取所有电话号码为 fromNumber
或 toNumber
的文档.我现在的电话是:
I'm trying to get all the documents that have my phone number as the fromNumber
or the toNumber
. My call right now is:
database.collection('documents').where('fromNumber','==',myPhoneNumber).get().then();
不是进行2次调用,而是一次检查fromNumber和第二次检查toNumber,如何同时在同一 .get()
中进行检查?
Instead of making 2 calls, one to check the fromNumber and the second one to check the toNumber, how can I check both at the same time and in the same .get()
?
顺便说一句:测试了此代码:
Btw: tested this code:
database.collection('documents')
.where('fromNumber','==',myPhoneNumber)
.where('toNumber','==',myPhoneNumber).get()
.then();
但是它会检查两者是否都正确,这是我正在寻找的 AND
而不是 OR
.
But it checks if both are true, it's an AND
instead of the OR
I'm looking for.
推荐答案
根据官方文档,有一些查询限制,涉及到Firestore:
According to the official documentation, there a are some query limitations, when it comes to Firestore:
Cloud Firestore不支持以下类型的查询:
Cloud Firestore does not support the following types of queries:
逻辑或查询.在这种情况下,您应该为每个OR条件创建一个单独的查询,然后将查询结果合并到您的应用中.
Logical OR queries. In this case, you should create a separate query for each OR condition and merge the query results in your app.
按照文档中的建议,您应该创建两个单独的查询并合并结果客户端.
As suggested in the documentation, you should create two separate queries and merge the result cliend side.
这篇关于Firebase获取数据比较两个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!