Database IntegrationLesson 63Free preview
MongoDB Find
This lesson is part of Node.js · All levels
Summary
This lesson discusses reading MongoDB data from Node.js with find(), find().findOne(), and converting the results to arrays. Cursors support chaining such as sort(), limit(), and project() to filter out results. It's also important to understand ObjectId so that a search based on _id doesn't fail.
Key points
- Find(filter) returns the cursor; toArray() pulls all the matching results.
- Returns a document or a unique field, suitable for searching by _id.
- Import the objectId from the mongodb module to search for the objectId type.
- Chaining limit(), skip(), sort(), project() sets the number, sequence, and column of results.
- An empty filter means taking all the documents; be careful with the large collection.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.