Skip to content

Instantly share code, notes, and snippets.

@mcshakes
Last active April 18, 2018 00:53
Show Gist options
  • Save mcshakes/1e3e0ac9ef8094dac2b00ce3a5aed799 to your computer and use it in GitHub Desktop.
Save mcshakes/1e3e0ac9ef8094dac2b00ce3a5aed799 to your computer and use it in GitHub Desktop.
1) Find All
db.restaurants.find()
2)Limit and Sort
db.restaurants.find().sort({'name': 1}).limit(10)
3)Find by Object ID
db.restaurants.find(ObjectId("59074c7c057aaffaafb0da6d"))
4) Get by Value
db.restaurants.find({ borough: "Queens" })
5) Count
db.restaurants.count()
6) Find by nested value:
db.restaurants.find({ "address.zipcode": "11206" }).count()
7)Delete by ID
db.restaurants.deleteOne({ _id: ObjectId("59074c7c057aaffaafb11cb2")})
8) Update
db.restaurants.update({
... _id: ObjectId("59074c7c057aaffaafb11c28")
... },{
... name: "Poop Chute"
... });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment