3

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

Jeach
  • 8,656
  • 7
  • 45
  • 58
TimTheEnchanter
  • 3,370
  • 1
  • 26
  • 47

1 Answers1

5

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" } )

TimTheEnchanter
  • 3,370
  • 1
  • 26
  • 47
  • 1
    I'm confused, this is the exact same syntax you mention in `Update` of the question where you say it doesn't work...? – Gabe O'Leary Jul 31 '20 at 19:31
  • Had same question ... I confirm this does work (in lokijs 1.5.12)!! – Jeach May 01 '23 at 18:43
  • @GabeO'Leary, I just edited the question in order to remove all confusion and stop people from down voting the it (probably due to this issue). I have validated that it does work. I have upvoted this answer, and upvoted the question after edit. Hope it helps to clarify things. – Jeach May 01 '23 at 18:48