BSA Lection - 3: MongoDB
This lesson was completed with use of Studio 3T.
- A query to search for all students who's score > 87% and < 93% for any of the types of completed assignments(query result):
db.philippLypniakov.find({
"scores": {
$elemMatch: {
"score": {
$gt: 87,
$lt: 93
}
}
}
});
- Write an aggregation query to select all students who have a test result (type: "exam") of more than 90% (use unwind)(query result):
db.philippLypniakov.aggregate(
// Pipeline
[
// Stage 1
{
$unwind: {
path : "$scores"
}
},
// Stage 2
{
$match: {
"scores.type" : "exam",
"scores.score" : { $gt : 90 }
}
},
]
);
- Modify Dusty Lemmond's documents(query result; acknowledgement result):
//Update Dusty Lemmond documents
db.philippLypniakov.updateMany(
{name : "Dusti Lemmond"},
{$set : { "accepted" : true } }
);
//Return Dusty's documents
db.philippLypniakov.find({
"name": "Dusti Lemmond"
});