Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- These commands and drills refer to the restaurants db in Node Unit 2 Lesson 1
- Retrieve all restaurants:
- db.restaurants.find( {} )
- Retrieve the first 10 restaurants sorted alphabetically by name:
- db.restaurants.find({}).sort({name: 1}).limit(10)
- Get a restaurant by _id: (Text isn't clear whether they mean _id or restaurant_id)
- db.restaurants.find({_id: ObjectId("58d59a0611262b867976c684")})
- How many restaurants are in db.restaurants?
- db.restaurants.find({}).count()
- Number of restaurants with zipcode 11206
- db.restaurants.find({'address.zipcode': '11206' } } ).count()
- Delete one record or document from restaurants:
- db.restaurants.deleteOne(ObjectId('blahblah'))
- Write a command that sets the name property of a document with a specific _id to
- 'Bizz Bar Bang'. Make sure that you're not replacing the existing document, but instead updating only the name property.
- db.restaurants.updateOne({_id: ObjectId('booboo')}, {$set: {"name":"Foo Bar Bizz"}})
- Update all restaurants with zipcode 10035 to zipcode 10036:
- db.restaurants.updateMany({ address: { zipcode: "10035" }, { $set: { zipcode: "10036"}}})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement