Created
March 27, 2018 19:05
-
-
Save 821jieun/6f47429ae3d4676fa2a591407df185e6 to your computer and use it in GitHub Desktop.
Mongo basic drills- https://courses.thinkful.com/node-001v5/project/2.1.3
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); | |
//find by id | |
var myId = db.restaurants.findOne({}, {_id: true})._id; | |
db.restaurants.findOne({_id: myId}); | |
//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 | |
var myId = db.restaurants.findOne({}, {_id: true})._id; | |
db.restaurants.deleteOne({_id: myId}); | |
//update a single document | |
var myId = db.restaurants.findOne({}, {_id: true})._id; | |
db.restaurants | |
.updateOne({ | |
{ id : myId }, | |
{$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