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

188
Vistas
How write firestore query filter for array of objects?

I am writing a query in react native to get data from firestore by filtration of friends by friend name ... Like get all useers where friendName is XYZ

[
{User: 'Johan', friends:[{friendName: 'ABC', age:20}, {friendName: 'DEF', age:30},{friendName: 'XYZ', age:25}]}, 

{User: 'Johnson', friends:[{friendName: 'ABC', age:20}, {friendName: 'XYZ', age:25}]},

{User: 'Symonds', friends:[{friendName: 'DEF', age:30},{friendName: 'XYZ', age:25}]}
]

I am trying with code like this by is not working. As I need to mention to filter with friendName but not able to find how to write this in query.

usersRef
    .doc(userId)
    .collection("Users")
    .where('friends', 'array-contains','ABC')
    .get();

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

as long as I Know you can't query fields inside objects. My approach would be querying user's id, and then iterate resulting array.

//First make a query 
let resultsArray=[]
usersRef.doc(userId).collection("Users").get().then((docs)=>{
 this.resultsArray.push(docs)
})

//after query is done, iterate results
this.resultsArray.foreach((item)=>{
  item.data().friends.foreach((friend)=>{
    if(friend.friendName === 'ABC'){
      //yes, your friend name is ABC, do whatever you need.
    }
 )
})
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