Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. These commands and drills refer to the restaurants db in Node Unit 2 Lesson 1
  2.  
  3. Retrieve all restaurants:
  4. db.restaurants.find( {} )
  5.  
  6. Retrieve the first 10 restaurants sorted alphabetically by name:
  7. db.restaurants.find({}).sort({name: 1}).limit(10)
  8.  
  9. Get a restaurant by _id: (Text isn't clear whether they mean _id or restaurant_id)
  10. db.restaurants.find({_id: ObjectId("58d59a0611262b867976c684")})
  11.  
  12. How many restaurants are in db.restaurants?
  13. db.restaurants.find({}).count()
  14.  
  15. Number of restaurants with zipcode 11206
  16. db.restaurants.find({'address.zipcode': '11206' } } ).count()
  17.  
  18. Delete one record or document from restaurants:
  19. db.restaurants.deleteOne(ObjectId('blahblah'))
  20.  
  21. Write a command that sets the name property of a document with a specific _id to
  22. 'Bizz Bar Bang'. Make sure that you're not replacing the existing document, but instead updating only the name property.
  23. db.restaurants.updateOne({_id: ObjectId('booboo')}, {$set: {"name":"Foo Bar Bizz"}})
  24.  
  25. Update all restaurants with zipcode 10035 to zipcode 10036:
  26. db.restaurants.updateMany({ address: { zipcode: "10035" }, { $set: { zipcode: "10036"}}})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement