Mongosh commands (MongoDB)

PHOTO EMBED

Sat Aug 28 2021 16:52:53 GMT+0000 (Coordinated Universal Time)

Saved by @13tinydots #plaintext

INSERTING ONE AND MANY
db.places.insertOne({})
db.places.insertMany({})

UPDATING - ONE AND MANY
db.places.updateOne({"country": "India"}, {$set: {"continent": "Europe"}})
db.places.updateMany({"country": "India"}, {$set: {"flag": "Updated Flag"}})

DELETING
db.places.deleteOne({"continent": "Africa"})
db.places.deleteMany({"continent": "Africa"})
db.places.findAndDelete({})

FINDING
db.students.find({"name":"Andy"})
db.students.find({"name":"Mike"})

FINDING using $OR and $IN
this will return entries that have hobbies of baseball OR MAC and Linux users
db.students.find( { $or: [ { "hobbies": { $in: ["Baseball"]}}. { "os" { $in: ["Mac", "Lin"]}}]})

also compatible with SOME regex expressions

SORTING:
db.animals.find().sort({weight: -1}); <== this is descending, a positive value is ascending



content_copyCOPY