Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

340
Views
How i can use a query in a multiple time with firebase?

My console log is 2 differents id : sender.id and otherparticipants[0].id

I need to query my first document with sender.id OR otherParticipants (because it could be one or another one)

I'm trying to do that with an operator OR but firebase seems doesn't recognize my second value.

Do you know how I can have the same result in a good way?

.then(() => {
      console.log('participant', otherParticipants[0].id, sender.id);
      firebase
        .firestore()
        .collectionGroup('favoris')
        .where('id', '==', sender.id || otherParticipants[0].id)
        .get()
        .then((querySnapshot) => {
          querySnapshot.forEach((doc) => {
            console.log('data2', doc.data());
            firebase
              .firestore()
              .collectionGroup('favoris')
              .where('idUser', '==', sender.id || otherParticipants[0].id)
              .get()
              .then((querySnapshot) => {
                console.log(querySnapshot.size);
                querySnapshot.forEach((doc) => {
                  console.log('dataFinal', doc.data());

                  socialFeedsRef
                    .doc(sender.id)
                    .collection('chat_feed')
                    .doc(channel.id)
                    .set(
                      {
                        favoris: true,
                      },
                      { merge: true },
                    );
                });
              });
          });
        });
    });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

That's not how you should create an OR query in Firestore:

.where('id', '==', sender.id || otherParticipants[0].id)

In this line, the || operator doesn't help.


You should create an array containing the IDs of the users who participate in the chat, say participantIDs: ["yourSenderUID", "yourOtherUid"].

Then, instead of the above call, add the following one:

.where("participantIDs", "array-contains-any", [sender.id, otherParticipants[0].id])

When you execute such a query, you'll get a warning message that sounds like this:

FAILED_PRECONDITION: The query requires a COLLECTION_GROUP_ASC index for collection favoris and field id. You can create it here: ...

Meaning that an index is required. You can simply click on that URL, or copy and paste the URL into a web browser and your index will be created automatically for you.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!