Skip to content

Instantly share code, notes, and snippets.

@michaelablackham
Created August 16, 2017 01:59
Show Gist options
  • Select an option

  • Save michaelablackham/e6ef30bfd3d1f09f210a6c36ca907a2c to your computer and use it in GitHub Desktop.

Select an option

Save michaelablackham/e6ef30bfd3d1f09f210a6c36ca907a2c 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.
find({"_id": ObjectId("599399ad535efc3e9694cf4a")})
//Get by Value
db.restaurants.find({cuisine: "Irish"});
//Count
db.restaurants.count()
//Count by nester value
db.restaurants.find({'grades.grades': 'A'}).count()
//Delete by ID
db.restaurants.remove({_id: ObjectId("599399ad535efc3e9694cf4a")});
//Update single document
db.restaurants.updateOne(
{_id: ObjectId("599399ad535efc3e9694cf4a")},
{$set: {name: 'Bizz Bar Bang'}});
//Update many documents
db.restaurants.updateMany(
{'borough': 'Manhattan'},
{$set: {'borough': 'Brooklyn'}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment