Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- To move into a db - use database name
- to get the collections names in said db - db.getCollectionNames()
- To get all of the files in the collection - db.collectionname.find()
- command that makes the first 10 restaurants appear when db.restaurants is alphabetically sorted by the name property - db.collectionname.find().sort({name:1}).limit(10);
- Get by id
- first get the id using: db.restaurants.findOne({}, {_id: 1})._id
- Then get the whole object using: db.restaurants.findOne({_id: objectId})
- Get by value
- db.restaurants.find({borough: "Queens"})
- Count
- db.restaurants.count()
- Count by nested value
- finding by nested value: db.restaurants.find( {"address.zipcode": "10003"})
- then counting it, chain the count: db.restaurants.find( {"address.zipcode": "10003"}).count()
- Delete by Id
- db.restaurants.deleteOne({_id: objectId})
- Update a property
- db.restaurants.updateOne({_id: objectId}, {$set: {name: "Bizz bar Bang"}})
- Update many properties
- db.restaurants.updateMany({"address.zipcode": "10035"}, {$set: {"address.zipcode": "10036"}})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement