Guest User

Untitled

a guest
Mar 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. 1. Find the command that retrieves all restaurants.
  2.  
  3. db.restaurants.find()
  4.  
  5. 2. Find the command that makes the first 10 restaurants appear when db.restaurants is alphabetically sorted by the name property.
  6.  
  7. db.restaurants.
  8. find().
  9. sort({name: 1}).
  10. limit(10);
  11.  
  12. 3. Retrieve a single restaurant by _id from the restaurants collection. This means you'll first need to get the _id for one of the restaurants imported into the database.
  13.  
  14. var documentId = ObjectId('59074c7c057aaffaafb10c04');
  15. db.restaurants.findOne({_id: documentId});
  16.  
  17. 4. Write a command that gets all restaurants from the borough of "Queens".
  18. db.restaurants.find({"borough": "Queens"});
  19.  
  20. 5. Write a command that gives the number of documents in db.restaurants.
  21. db.restaurants.count()
  22.  
  23. 6. Write a command that gives the number of restaurants whose zip code value is '11206'. Note that this property is at document.address.zipcode, so you'll need to use dot notation to query on the nested zip code property.
  24. db.restaurants.find({"address.zipcode":"11206"});
  25.  
  26. 7. Write a command that deletes a document from db.restaurants. This means you'll first need to get the _id for one of the restaurants imported into the database.
  27. var documentId = ObjectId('59074c7c057aaffaafb10c04');
  28. db.restaurants.remove({_id: documentId});
  29.  
  30. 8. 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.
  31.  
  32. var myId = db.restaurants.findOne({}, {_id: true})._id;
  33. db.restaurants.updateOne(
  34. {_id: myId},
  35. {$set: {name: 'Bizz Bar Bang'}});
  36.  
  37. 9.Uh oh, two zip codes are being merged! The '10035' zip code is being retired, and addresses with '10035' will now fall under the '10036' zip code. Write a command that updates values accordingly.
  38.  
  39. db.restaurants.updateMany(
  40. {'address.zipcode': '10035'},
  41. {$set: {'address.zipcode': '10036'}});
Add Comment
Please, Sign In to add comment