Created
October 9, 2018 23:05
-
-
Save theGaffe/0ab59e84efe7ce0162b6967d61c23ce8 to your computer and use it in GitHub Desktop.
Mongo basics drills
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 id = db.restaurants.findOne()._id | |
db.restaurants.findOne({_id: id}}) | |
//Get by value | |
db.restaurants.find({borough: "Queens"}) | |
//Count | |
db.restaurants.count() | |
//Count by nestest value | |
db.restaurants.find({"address.zipcode": "11206"}).count() | |
//Delete by id | |
var id = db.restaurants.findOne()._id | |
db.restaurants.deleteOne({_id: id}) | |
//Update a single document | |
var id = db.restaurants.findOne()._id | |
db.restaurants.updateOne( { _id: id}, {$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