I have a document like this one:
{
"_id" : 0,
"name" : "aimee Zank",
"scores" : [
{
"type" : "exam",
"score" : 1.463179736705023
},
{
"type" : "quiz",
"score" : 11.78273309957772
},
{
"type" : "homework",
"score" : 6.676176060654615
},
{
"type" : "homework",
"score" : 35.8740349954354
}
]
}
On that document I want to delete the score that has the lowest score of type homework. First, I'm trying to do it on the mongo shell, so I put the values manually.
db.students.update({ _id:0}, {$unset: {"scores.score":6.676176060654615} })
That query does nothing, so I tried to search on Google and I found here a question about removing an object from an array and I tried this other query:
db.students.update({ _id:0 }, { $unset:
{ "scores": {
"homework": 6.676176060654615 } } }, false, true);
The second query worked, but not as I expected because the result was
{ "_id" : 0, "name" : "aimee Zank" }
To check that the lowest value of type homework exists I find with this query:
db.students.find({"scores.score":6.676176060654615}).pretty();