Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I query nested object by property inside an array?

Tags:

lokijs

I have a collection of several thousand (potentially 30-40k) documents, with a structure (greatly simplified) like this:

{
 propA:'123',
 obj: [
       {prop1:'a'},
       {prop1:'b'},
       {prop1:'c'}
 ],
 propB:456
}

How can I query to find all documents where obj.prop1==='b'? I can't seem to figure out how to check a property of an object inside an array property. This is using version 1.5.1.

Thanks!

Update Resolved - see my answer...

like image 338
TimTheEnchanter Avatar asked Feb 17 '26 10:02

TimTheEnchanter


1 Answers

I needed to include the nested property name in quotes in my query. The query example I tried in Mongo does actually work in Loki if you include the object.propName in quotes, so this DOES work: myCollection.find( { "obj.prop1": "b" } )

like image 160
TimTheEnchanter Avatar answered Feb 21 '26 14:02

TimTheEnchanter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!