paralect/node-mongo

Add option to #find to fetch only specified fields

Closed this issue · 2 comments

Projection object from the docs
https://docs.mongodb.com/manual/reference/method/db.collection.find/

Support for projection is needed in order to limit network traffic by removing useless fields when fetching collections or large objects.

@IharKrasnik Options in find method passed directly to the monk. So you can do projections like this:

users.find({}, 'name').then((docs) => {
  // only the name field will be selected
})
users.find({}, { fields: { name: 1 } }) // equivalent

users.find({}, '-name').then((docs) => {
  // all the fields except the name field will be selected
})
users.find({}, { fields: { name: 0 } }) // equivalent

@anorsich Got it! It is another issue then
#4