scottfontenot
10/24/2017 - 11:40 PM

mongoBasicDrills.md

Get All:

db.restaurants.find();

Limit and Sort:

db.restaurants.find().sort({name: 1}).limit(10)

Get 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 Variables:

db.restaurants.find({'address.zipcode': '11206'}).count()

Delete by ID:

db.restaurants.deleteOne({_id: ObjectId("59074c7c057aaffaafb0dbb1")})

Update One Document:

db.restaurants.updateOne({_id: myId}, {$set: {name: 'Pork Stand'}})

Update Many Documents:

db.restaurants.updateMany({'address.zipcode': '10035'}, {$set: {'address.zipcode': '10036'}})