Created
June 20, 2017 23:16
-
-
Save tian-chaiyaporn/54caef4f30617a15578103f33e4383bf 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
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