Skip to content

Instantly share code, notes, and snippets.

@escottalexander
Created September 21, 2018 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save escottalexander/ceea826c27ce3e359b294b53c6b730e2 to your computer and use it in GitHub Desktop.
Save escottalexander/ceea826c27ce3e359b294b53c6b730e2 to your computer and use it in GitHub Desktop.
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