Skip to content

Instantly share code, notes, and snippets.

@rjwilliams87
Created October 9, 2018 23:26
Show Gist options
  • Save rjwilliams87/e2974396e89517d1c86f1461f8d1ebc7 to your computer and use it in GitHub Desktop.
Save rjwilliams87/e2974396e89517d1c86f1461f8d1ebc7 to your computer and use it in GitHub Desktop.
Get All: db.restaurants.find();
Limit and Sort: db.restaurants.find().sort({name:1}).limit(10);
Get by _id: db.restaurants.findOne({_id: ObjectId(...)});
Get by value: db.restaurants.find({borough: "Queens"});
Count: db.restaurants.count();
Count by nested value: db.restaurants.count({"address.zipcode" : "11206});
Delet by Id: db.restaurants.remove({_id: ObjectId(...)});
Update a single document: db.restaurants.update({_id: ObjectId(...)}, {$set: {name: "Foo Bar Bizz Buzz"}});
Update many documents: db.restaurants.updateMany({"address.zipcode": "10035"}, {$set: {"address.zipcode": "10036"}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment