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 Projections operators #3

Open
Arilas opened this issue Sep 29, 2021 · 0 comments
Open

Query Projections operators #3

Arilas opened this issue Sep 29, 2021 · 0 comments
Assignees
Milestone

Comments

@Arilas
Copy link
Owner

Arilas commented Sep 29, 2021

MongoDB has the ability to specify the second parameter to find() function, which allows making a projection of result, by modifying it.

For example:

db.schools.find( { zipcode: "63109" },
                 { students: { $elemMatch: { school: 102 } } } )

The operation returns the documents that have zipcode equal to 63109 and projects the students array using $elemMatch, so it will contain the first item that match project or don't include this array at all:

{ "_id" : 1, "students" : [ { "name" : "john", "school" : 102, "age" : 10 } ] }
{ "_id" : 3 }
{ "_id" : 4, "students" : [ { "name" : "barney", "school" : 102, "age" : 7 } ] }

Also it is possible to use $, $slice, 1 and 0 operators

We should make it possible to use this with Array.map, so buildFilter will also can return a mapper.

@Arilas Arilas self-assigned this Sep 29, 2021
@Arilas Arilas added this to the v1.1.0 milestone Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant