sergeyksv / tingodb

Embedded Node.js database upward compatible with MongoDB
www.tingodb.com
1.16k stars 105 forks source link

Query for an Element by the Array Index Position does not work #150

Open ghost opened 7 years ago

ghost commented 7 years ago

See: https://docs.mongodb.com/manual/tutorial/query-arrays/#query-for-an-element-by-the-array-index-position

Example query:

const inventory = db.collection('inventory')

await inventory.insertMany([
   { item: "journal", qty: 25, tags: ["blank", "red"], dim_cm: [ 14, 21 ] },
   { item: "notebook", qty: 50, tags: ["red", "blank"], dim_cm: [ 14, 21 ] },
   { item: "paper", qty: 100, tags: ["red", "blank", "plain"], dim_cm: [ 14, 21 ] },
   { item: "planner", qty: 75, tags: ["blank", "red"], dim_cm: [ 22.85, 30 ] },
   { item: "postcard", qty: 45, tags: ["blue"], dim_cm: [ 10, 15.25 ] }
])

await inventory.find( { "dim_cm.1": { $gt: 25 } } ).toArray()

I will probably provide a test for this soon and see if I can fix it.

sclark39 commented 7 years ago

This worked for me, but only when querying an array of embedded documents. db.users.find( { 'info.0.follows_viewer': true } )

while this didn't work: db.users.find( { 'info.follows_viewer': true } )