Mongo Shell Practice

Goal

Using the mongo shell, you will perform all possible CRUD operations on a database collection of candies.

To begin:

  1. Open a new terminal window and run mongo
  2. Create a new database with db use demo
  3. Make your first entry to a new collection: db.candies.insertOne({name: "Snickers", price: 1.5, quantity: 5, eaten: false })

Requirements

Refer to the documentation for all the query methods available in the Mongo shell. Use Compass to test that your database is being updated properly.

Create

  1. Insert a single candy
  2. Insert at least 3 candies all in one command

Read

  1. Query all candies
  2. Query all candies by name of your choice
  3. Query one candy by ID

Update

  1. Change the price of a single candy using ID
  2. Change the name of eaten property to true on every candy

Delete

  1. Delete a single candy by Id
  2. Delete all candies with a quantity greater than 2
  3. Delete all candies