Skip to content

Instantly share code, notes, and snippets.

@tian-chaiyaporn
Created June 20, 2017 23:16
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 tian-chaiyaporn/54caef4f30617a15578103f33e4383bf to your computer and use it in GitHub Desktop.
Save tian-chaiyaporn/54caef4f30617a15578103f33e4383bf 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:
var docId = db.restaurants.findOne({})._id;
then db.restaurants.find({_id: docId})
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.remove({_id: id}, {justOne: true})
Update a single document:
var docId = db.restaurants.findOne({})._id;
db.restaurants.updateOne(
{_id: docId},
{$set: {name: 'Bizz Bar Bang'}});
Update many documents:
db.restaurants.updateMany(
{'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