這是我收集的樣子從文檔數組中刪除最低分數:無法在MongoDB中
db.students.find({_id:100}).pretty()
{
"_id" : 100,
"name" : "Demarcus Audette",
"scores" : [
{
"type" : "exam",
"score" : 30.61740640636871
},
{
"type" : "quiz",
"score" : 14.23233821353732
},
{
"type" : "homework",
"score" : 31.41421298576332
},
{
"type" : "homework",
"score" : 30.09304792394713
}
]
}
我執行以下2個查詢在蒙戈外殼:
x=db.students.aggregate([{ "$unwind":"$scores" },{"$match":{"scores.type":"homework"}},{ "$group":{"_id":"$_id","minscore":{"$min":"$scores.score" }}} ])
和未來一個是:
for (var a in x["a"]) { db.students.update({ "_id":a["_id"] },{"$pull":{"scores":{"score":a["minscore"]}}}) }
我能夠看到最低分數列表,但是當我執行第二個查詢時似乎沒有任何東西刪除。我知道有一個邏輯錯誤。我試圖在這裏閱讀帖子,但我無法通過它。我只是想知道我哪裏錯了。
這是第4周的MongoDB for java開發者課程的作業! –