Firebase get data compare two fields

2019-08-17 14:56发布

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();

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();

But it checks if both are true, it's an AND instead of the OR I'm looking for.

1条回答
Root(大扎)
2楼-- · 2019-08-17 15:39

According to the official documentation, there a are some query limitations, when it comes to Firestore:

Cloud Firestore does not support the following types of queries:

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.

查看更多
登录 后发表回答