1

Is it possible in firebase firestore to get information about the multiple documents are available or using where query we are using react native.

userRef.where('number', '==', '123')
    .where('number', '==', '1234')
    .get()
    .then(r =>{

      r.forEach(n => console.log(n))

    });

is it possible to get those two documents in response ?

if I use like single where its working fine, how can I use same thing for nested documents compare ?

1 Answer 1

4

If I understand your use-case correctly, you want to get exactly two users, where user one has the number 123 and user two has the number 1234.

Such query to my understanding is currently not possible with Firestore, but you can split them up into two queries and merge the result.

const userOne = userRef.where('number', '==', '123').get();
const userTwo = userRef.where('number', '==', '1234').get();

Promise.all([userOne, userTwo])
.then(result => {
    /*
    * expected output: Array [QuerySnapshot, QuerySnapshot]
    * First QuerySnapshot is result from userOne "where"
    * Second QuerySnapshot is result from UserTwo "where"
    */

    const userOneResult = result[0];
    const userTwoResult = result[1];

    if (userOneResult.empty === false && userTwoResult.empty === false) {
        // Get both your users here
    }
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.