daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Feb 16th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GET ALL
  2. db.restaurants.find();
  3.  
  4. LIMIT AND SORT
  5. db.restaurants.
  6.   find().
  7.   sort({name: 1}).
  8.   limit(10);
  9.  
  10. GET BY ID
  11. var myId = db.restaurants.findOne({}, {_id: true})._id;
  12. db.restaurants.findOne({_id: myId});
  13.  
  14. GET BY VALUE
  15. db.restaurants.find({borough: "Queens"});
  16.  
  17. COUNT
  18. db.restaurants.count();
  19.  
  20. COUNT BY NESTED
  21. db.restaurants.find({'address.zipcode': '11206'}).count()
  22.  
  23. DELETE BY ID
  24. var myId = db.restaurants.findOne({}, {_id: true})._id;
  25. db.restaurants.removeOne({_id: myId});
  26.  
  27. UPDATE
  28. var myId = db.restaurants.findOne({}, {_id: true})._id;
  29. db.restaurants.updateOne(
  30.   {_id: myId},
  31.   {$set: {name: 'Bizz Bar Bang'}});
  32.  
  33. UPDATE MANY
  34. db.restaurants.updateMany(
  35.   {'address.zipcode': '10035'},
  36.   {$set: {'address.zipcode': '10036'}});
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top