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.
- Update a single document with $set
- Use $inc to increment a counter
- Delete documents matching a condition
// Update product price // Increment product stock // Delete out-of-stock products