M101JS: MongoDB for Node.js Developers (Week 2: CRUD)

On to week 2 of the MongoDB University course! Here are my notes for this week…

Creating Documents

  • db.collection.insert()

The _id Field

  • Automatically generated unique key
  • Can be specified by user when the object is created
  • Duplicate keys generate an error

Reading Documents

  • .find({query})

Homework: Multiple selectors in a find() command, Simple projection, Matching a specific, Array element, Arrays with nested documents

Comparison Operators, Element Operators, Logical Operators, Regex Operator, Array Operators

Homework: Equality queries on arrays, Array operators

Challenge Exercise: Arrays with nested documents

  • Another ungraded challenge, but it is testing some of the db query skills that have been covered so far in the course.

Updating Documents

  • The longest of the lectures so far in the course. This lecture covers a lot of ground with .updateOne(), .updateMany(), and .replaceOne()

Homework: Updating scalar fields, Updating based on multiple criteria