Created
August 4, 2018 20:46
-
-
Save ukhlivanov/5570709105733299e1735bdaf1c5996e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get all | |
db.restaurants.find(); | |
//Limit and sort | |
db.restaurants. | |
find({borough: "Manhattan"}, {_id: 1, name: 1, address: 1}). | |
sort({name: 1}). | |
limit(10); | |
//Get by _id | |
db.restaurants.find({ _id: ObjectId("59074c7c057aaffaafb0da9d")}); | |
//Get by value | |
db.restaurants.find({borough:"Queens"}); | |
//Count objects | |
db.restaurants.count(); | |
//Count by nested value | |
db.restaurants.find({"address.zipcode": 11206}); | |
//Delete by id | |
db.restaurants.deleteOne({_id: ObjectId("59074c7c057aaffaafb0da9d")}); | |
//Update a single document | |
var objectId = db.restaurants.findOne({}, {_id: 1})._id | |
db.restaurants.updateOne( | |
{_id: objectId}, | |
{$set: {name: "Bizz Bar Bang"}} | |
); | |
//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