Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem
- Find the command that retrieves all restaurants
- //Solution
- mongo
- use tempTestDb
- db.restaurants.find()
- //problem
- Find the command that makes the first 10 restaurants appear when db.restaurants is alphabetically sorted by the name property
- //Solution
- db.restaurants.find().sort({name: 1}).limit(10)
- //Problem
- Retrieve a single restaurant by _id from the restaurants collection
- //Solution
- db.restaurants.findOne({_id: ObjectId("59074c7c057aaffaafb0e20b")})
- //Problem
- Write a command that gets all restaurants from the borough of "Queens".
- //Solution
- db.restaurants.find({borough: "Queens"})
- //Problem
- Write a command that gives the number of documents in db.restaurants.
- //Solution
- db.restaurants.count()
- //Problem
- rite a command that gives the number of restaurants whose zip code value is '11206'
- //Solution
- db.restaurants.find({'address.zipcode': '11206'}).count()
- //Problem
- Write a command that deletes a document from db.restaurants
- //Solution
- db.restaurants.remove({_id: ObjectId("59074c7c057aaffaafb0dbba")})
- //Problem
- Write a command that sets the name property of a document with a specific _id to 'Bizz Bar Bang'.
- //Solution
- db.restaurants.updateOne({_id: ObjectId("59074c7c057aaffaafb0dbb1")}, {$set: {name: 'Foo Bar Bizz Bang'}})
- //Problem
- update many documents
- //Solution
- db.restaurants.updateMany({'address.zipcode': '10035'}, {$set: {'address.zipcode': '10036'}})
Add Comment
Please, Sign In to add comment