Script Valley
MongoDB: Complete Course
CRUD Operations/Assessment

Practice & Assessment

Test your understanding of CRUD Operations

Multiple Choice Questions

5
1

You call insertMany with 5 documents using default options. Document 3 has a duplicate _id. What happens?

2

Which update operation atomically increases a numeric field by 5?

3

What is the difference between collection.drop() and deleteMany({})?

4

Which operator would you use to find orders where at least one item has sku='X' AND qty > 2?

5

What does setting upsert:true do in updateOne?

Coding Challenges

1
1

Product Inventory CRUD CLI

Write a Node.js script using the mongodb driver that performs these operations on a 'products' collection: (1) Insert 5 products with name, price, category, and stock fields. (2) Query all products with price > 50 and print them. (3) Update the stock of the cheapest product by incrementing it by 10. (4) Delete all products where stock === 0. Print the deletedCount. All operations must use async/await and handle errors. Input: hardcoded product array. Output: query results and deletedCount printed to console. Estimated time: 25 minutes.

Easy

Mini Project

1

REST API with Full CRUD — Notes App

Build a Node.js + Express REST API for a notes application backed by MongoDB. Endpoints: POST /notes (create), GET /notes (list all, support ?category= filter), GET /notes/:id (get one), PATCH /notes/:id (update title or body with $set), DELETE /notes/:id (hard delete). Each note has title, body, category, createdAt, and updatedAt. Return proper HTTP status codes: 201 for create, 404 for not found, 400 for validation errors. No Mongoose — use the native driver. Test all endpoints with curl or Postman.

Medium