I'm aware of the function .equalTo(0)
in Firebase to find a result. However how can the same be achieved in a nested object? Let's say I have the following data in my Products
database:
Object {
"codes": Object {
"0": "12314241",
"1": "253525523523",
},
"name" : "hello",
...
}
Object {
"codes": Object {
"0": "4634347347473",
"1": "3562552335",
},
"name" : "bye",
...
}
If I just wanted to find an entry which isn't nested I could execute something like
db.ref('/products').orderByChild("name").equalTo("hello").once('value', querySnapShot => { if (querySnapShot.exists()) { ... } })
Now I want to see if a code
exists in any of my nested entries. How is this achieved? Is it possible to .equalTo()
on nested objects, I'm stuck.
I tried the following:
const search = "4634347347473"
await db
.ref('/products')
.once('value', querySnapShot => {
if (querySnapShot.exists()) {
querySnapShot.forEach((child) => {
let val = child.child("barcodes").val()
console.log(child)
})
}
})
I can't figure out how to find if an entry which I'm searching for exists in my any of my nested objects.
Thanks in advance, looking forward to learn.