Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

346
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda