Guest User

Untitled

a guest
Oct 18th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. //Problem
  2. Find the command that retrieves all restaurants
  3. //Solution
  4. mongo
  5. use tempTestDb
  6. db.restaurants.find()
  7.  
  8. //problem
  9. Find the command that makes the first 10 restaurants appear when db.restaurants is alphabetically sorted by the name property
  10. //Solution
  11. db.restaurants.find().sort({name: 1}).limit(10)
  12.  
  13. //Problem
  14. Retrieve a single restaurant by _id from the restaurants collection
  15. //Solution
  16. db.restaurants.findOne({_id: ObjectId("59074c7c057aaffaafb0e20b")})
  17.  
  18. //Problem
  19. Write a command that gets all restaurants from the borough of "Queens".
  20. //Solution
  21. db.restaurants.find({borough: "Queens"})
  22.  
  23. //Problem
  24. Write a command that gives the number of documents in db.restaurants.
  25. //Solution
  26. db.restaurants.count()
  27.  
  28. //Problem
  29. rite a command that gives the number of restaurants whose zip code value is '11206'
  30. //Solution
  31. db.restaurants.find({'address.zipcode': '11206'}).count()
  32.  
  33. //Problem
  34. Write a command that deletes a document from db.restaurants
  35. //Solution
  36. db.restaurants.remove({_id: ObjectId("59074c7c057aaffaafb0dbba")})
  37.  
  38. //Problem
  39. Write a command that sets the name property of a document with a specific _id to 'Bizz Bar Bang'.
  40. //Solution
  41. db.restaurants.updateOne({_id: ObjectId("59074c7c057aaffaafb0dbb1")}, {$set: {name: 'Foo Bar Bizz Bang'}})
  42.  
  43. //Problem
  44. update many documents
  45. //Solution
  46. db.restaurants.updateMany({'address.zipcode': '10035'}, {$set: {'address.zipcode': '10036'}})
Add Comment
Please, Sign In to add comment