Skip to content

Instantly share code, notes, and snippets.

@FrancesFisk
Last active May 11, 2018 20:41
Show Gist options
  • Select an option

  • Save FrancesFisk/50179a9d010b49b067c0e420a2ec414d to your computer and use it in GitHub Desktop.

Select an option

Save FrancesFisk/50179a9d010b49b067c0e420a2ec414d to your computer and use it in GitHub Desktop.
Get all
db.restaurants.find();
Limit and sort:
db.restaurants.
... find().
... sort({name: 1}).
... limit(5);
Get by _id:
db.restaurants.findOne({_id: ObjectId("59074c7c057aaffaafb10c04")});
Get by value:
db.restaurants.find({borough: "Queens"});
Count:
db.restaurants.count();
Count by nested value:
db.restaurants.find({"address.zipcode": "11206"}).count();
Delete by id:
db.restaurants.deleteOne({_id: ObjectId("59074c7c057aaffaafb0dbb7")});
Update a single document
db.restaurants.updateOne({_id: ObjectId("59074c7c057aaffaafb0dbb1"), {$set: {name: "Bizz Bar Bang"}});
Update many documents
db.restaurants.updateMany({address: {zipcode: "10035"}}, {$set: {zipcode: "10036"}});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment