Mongo Shell Practice
- Tools: Mongo Shell, Terminal, MongoDB Compass
- Install Compass
- Mongo Shell Documentation
Goal
Using the mongo
shell, you will perform all possible CRUD operations on a database collection of candies.
To begin:
- Open a new terminal window and run
mongo
- Create a new database with
db use demo
- 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
- Insert a single candy
- Insert at least 3 candies all in one command
Read
- Query all candies
- Query all candies by name of your choice
- Query one candy by ID
Update
- Change the price of a single candy using ID
- Change the name of
eaten
property totrue
on every candy
Delete
- Delete a single candy by Id
- Delete all candies with a quantity greater than 2
- Delete all candies