Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

343
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda