MongoDB and Building Real APIs
Weeks 16 and 17 covered MongoDB operations and the development of a complete API from scratch.
MongoDB CRUD Operations
Creating Documents
insertOne creates a single document. insertMany creates multiple at once. MongoDB generates a unique _id for each document automatically.
Documents are flexible. They can have different fields even in the same collection. No fixed schema unless you enforce one with Mongoose.
Reading Documents
find returns all matching documents. findOne returns the first match. Query operators filter results.
Comparison operators: $gt for greater than, $lt for less than, $gte and $lte for greater-than-or-equal-to and less-than-or-equal-to ranges. $in for matching any value in an array. $ne for not equal.
Logical operators: $and and $or combine conditions. Pattern matching with regular expressions.
Projection selects which fields to return. Limit and skip enable pagination.…