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

182
Views
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 answers
Answer question

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