Created
September 21, 2018 19:38
-
-
Save escottalexander/ceea826c27ce3e359b294b53c6b730e2 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
Show all restaurants | |
db.restaurants.find() | |
Show first ten sorted by name | |
db.restaurants. | |
find(). | |
sort({name: 1}). | |
limit(10); | |
Find by _id | |
db.restaurants.findOne({_id: db.restaurants.findOne({}, {_id: 1})._id}) | |
Find by value (borough: "Queens") | |
db.restaurants.find({borough: "Queens"}) | |
Count | |
db.restaurants.count() | |
Find count where zip === 11206 | |
db.restaurants.find({"address.zipcode":"11206"}).count() | |
Delete by _id | |
db.restaurants.deleteOne({_id: db.restaurants.findOne({}, {_id: 1})._id}) | |
Update single document | |
db.restaurants.updateOne( | |
{_id: db.restaurants.findOne({}, {_id: 1})._id}, | |
{$set: {name: "Bar Bizz Bang"}} | |
); | |
Update several documents | |
db.restaurants.update( | |
{"address.zipcode" : "10035"}, | |
{$set: {"address.zipcode": "10036"}}, | |
{multi: true} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment