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

225
Views
How can i get the elements from an array inside of json in firebase?

i have this structure, in it there is an json object and that object have an array of json objects

i need to ask to them if color1 is red for example btw

name:carla
data: {
   sign: "carly",
   tools: [{trait:color1, value:red}, {trait:color2, value:white}] }
},
name:dany
data: {
   sign: "dan",
   tools: [{trait:color1, value:blue}, {trait:color2, value:black}] 
}

so i want to get only the elements have color1 red, in this case only should i get first one element

i tried with this

query = query.where('data.tools', "array-contains", {trait: 'color1', value: 'red'})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your query fetches documents where data.tools contains that object. It does not filter that array. You'll need to parse that object yourself after fetching the docs:

const qSnap = await query.get();

qSnap.docs.forEach((doc) => {
  const item = doc.data().data.tools.find(t => t.trait === 'color1' && t.value == 'red');
  console.log(item)
})

If you are trying to find a specific tool in a document, then you can create a sub-collection for tools. That way, you can query for one specific and also update it directly if required.

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!