Skip to content

Instantly share code, notes, and snippets.

@kouameYao
Created May 7, 2024 08:32
Show Gist options
  • Save kouameYao/1d2bc174dc25571f8c0d9eb9c95bdcc0 to your computer and use it in GitHub Desktop.
Save kouameYao/1d2bc174dc25571f8c0d9eb9c95bdcc0 to your computer and use it in GitHub Desktop.
Please enter a MongoDB connection string (Default: mongodb://localhost/):
Current Mongosh Log ID: 6639e4bc72218249cf12686a
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.8.1
Using MongoDB: 7.0.9
Using Mongosh: 1.8.1
hospital> db.patients.insertMany([ { "name": "kouame", "age": 27, "history": [{ disease: "cold" }] }, { "name": "yao", "age": 24, "history": [{ disease: "headach" }] }, { "name": "jean", "age": 45, "history": [{ disease: "cold" }] }])
{
acknowledged: true,
insertedIds: {
'0': ObjectId("6639e59c72218249cf12686e"),
'1': ObjectId("6639e59c72218249cf12686f"),
'2': ObjectId("6639e59c72218249cf126870")
}
}
hospital> db.patients.updateOne({name: "kouame"}, {$set: {age: 30}})
{
acknowledged: true,
insertedId: null,
matchedCount: 1,
modifiedCount: 1,
upsertedCount: 0
}
hospital> db.patients.find({age: {$gt: 30}})
[
{
_id: ObjectId("6639e59c72218249cf126870"),
name: 'jean',
age: 45,
history: [ { disease: 'cold' } ]
}
]
hospital> db.patients.find({age: {$gte: 30}})
[
{
_id: ObjectId("6639e59c72218249cf12686e"),
name: 'kouame',
age: 30,
history: [ { disease: 'cold' } ]
},
{
_id: ObjectId("6639e59c72218249cf126870"),
name: 'jean',
age: 45,
history: [ { disease: 'cold' } ]
}
]
hospital> db.patients.deleteMany({"history.disease": "cold"})
{ acknowledged: true, deletedCount: 2 }
hospital>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment