Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Mar 27, 2017 · 1 comment
Open

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

ghost opened this issue Mar 27, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 27, 2017

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant