Practice: Update and Delete Operations · MongoDB

Ch 2 · MongoDB CRUD Operations — card 7 of 8.

Now practise changing and removing product documents. You will update one product's price, increase another product's stock level, and delete every product that has run out. A correct answer uses update operators rather than replacing whole documents, and a filter that matches only the out-of-stock products, so nothing else is removed by accident.

  1. Update a single document with $set
  2. Use $inc to increment a counter
  3. Delete documents matching a condition
// Update product price
// Increment product stock
// Delete out-of-stock products