Open ghost opened 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.
This worked for me, but only when querying an array of embedded documents. db.users.find( { 'info.0.follows_viewer': true } )
db.users.find( { 'info.0.follows_viewer': true } )
while this didn't work: db.users.find( { 'info.follows_viewer': true } )
db.users.find( { 'info.follows_viewer': true } )
See: https://docs.mongodb.com/manual/tutorial/query-arrays/#query-for-an-element-by-the-array-index-position
Example query:
I will probably provide a test for this soon and see if I can fix it.