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

How to get all first elements from all documents using find #232

Open
lisette-bouwmeester1 opened this issue Jan 5, 2022 · 0 comments
Open

Comments

@lisette-bouwmeester1
Copy link

Considering this example collection:

students <- mongo("students") students$insert(c( '{ "student" : 1, "grades" : [ 95, 92, 90 ] }', '{ "student" : 2, "grades" : [ 98, 100, 102 ] }', '{ "student" : 3, "grades" : [ 95, 110, 100] }'))

I am trying to get from all documents the first element in grade. I tried the following, but this gives as output NULL

students$find(query = '{}', fields = '{"grades.0" : true}')

Why doesn't this work in the field operator, as it does work in the query part when looking for the student with the first grade 98:

students$find(query = '{"grades.0" : 98}', fields = '{"student" : true}')

I don't understand what I do wrong. Thanks for your help!

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