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

333
Views
¿Cómo puedo usar una consulta en varias ocasiones con firebase?

El registro de mi consola tiene 2 ID diferentes: sender.id y otherparticipants[0].id

Necesito consultar mi primer documento con sender.id U otros Participantes (porque puede ser uno u otro)

Estoy tratando de hacer eso con un operador OR pero Firebase parece no reconocer mi segundo valor.

¿Sabes cómo puedo tener el mismo resultado en el buen sentido?

 .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

No es así como debe crear una consulta OR en Firestore:

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

En esta línea, el || El operador no ayuda.


Debe crear una matriz que contenga las ID de los usuarios que participan en el chat, por ejemplo, ID de participantIDs: ["yourSenderUID", "yourOtherUid"] .

Luego, en lugar de la llamada anterior, agregue la siguiente:

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

Cuando ejecute una consulta de este tipo, obtendrá un mensaje de advertencia que suena así:

FAILED_PRECONDITION: la consulta requiere un índice COLLECTION_GROUP_ASC para los favores de la colección y la identificación del campo. Puedes crearlo aquí: ...

Lo que significa que se requiere un índice. Simplemente puede hacer clic en esa URL o copiar y pegar la URL en un navegador web y su índice se creará automáticamente para usted.

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!