evanlucas / learnyoumongo

MongoDB workshop.
MIT License
306 stars 89 forks source link

Find Project exercise: incorrect example and resource link #68

Open VAggrippino opened 6 years ago

VAggrippino commented 6 years ago

In the Find Project exercise, we're supposed to return documents with only the name and age properties using the MongoDB Node.js Driver.

The example provided shows a projection argument to the collection's find() method and references the documentation for this method as a resource link. However, this is the method's implementation in Mongo Shell. The find() method in NodeJS doesn't have a projection argument. Instead, a projection is applied using the project() method on the Cursor returned by find().

An accurate example would look like this:

collection.find({
  name: 'foo'
}).project({
  name: 1,
  age: 1,
  _id: 0
})

References: