Created
November 14, 2018 06:14
-
-
Save ecarlson1201/1199c62257b96fd87773e5de7e3ae02d to your computer and use it in GitHub Desktop.
mongo drills
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().sort({name: 1}).limit(10) | |
Get by Value | |
db.restaurants.find({borough: "Queens"}) | |
Count | |
db.restaurants.count() | |
Count by Nested Value | |
db.restaurants.count({"address.zipcode": "11206"}) | |
Delete by ID | |
db.restaurants.deleteOne( { "_id" : ObjectId("563237a41a4d68582c2509da") } ) | |
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.update({"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