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

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

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 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