Skip to content

Query Projections operators #3

@Arilas

Description

@Arilas

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.

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions