Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. To move into a db - use database name
  2.  
  3. to get the collections names in said db - db.getCollectionNames()
  4.  
  5. To get all of the files in the collection - db.collectionname.find()
  6.  
  7. command that makes the first 10 restaurants appear when db.restaurants is alphabetically sorted by the name property - db.collectionname.find().sort({name:1}).limit(10);
  8.  
  9. Get by id
  10. first get the id using: db.restaurants.findOne({}, {_id: 1})._id
  11. Then get the whole object using: db.restaurants.findOne({_id: objectId})
  12.  
  13. Get by value
  14. db.restaurants.find({borough: "Queens"})
  15.  
  16. Count
  17. db.restaurants.count()
  18.  
  19. Count by nested value
  20. finding by nested value: db.restaurants.find( {"address.zipcode": "10003"})
  21. then counting it, chain the count: db.restaurants.find( {"address.zipcode": "10003"}).count()
  22.  
  23. Delete by Id
  24. db.restaurants.deleteOne({_id: objectId})
  25.  
  26. Update a property
  27. db.restaurants.updateOne({_id: objectId}, {$set: {name: "Bizz bar Bang"}})
  28.  
  29. Update many properties
  30. db.restaurants.updateMany({"address.zipcode": "10035"}, {$set: {"address.zipcode": "10036"}})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement