【发布时间】:2015-04-03 21:07:59
【问题描述】:
学校数据库中有 200 个文档。我必须删除每个具有 "type":"homework" 和最低分数的文档。
{
"_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
}
]
}
例如,这里
{
"type" : "homework",
"score" : 6.676176060654615
}
必须删除,因为 score = 6.6
我把所有的文档都这样排序:
db.students.find({"scores.type":"homework"}).sort({"scores.score":1})
但我不知道如何删除分数最低的文档并键入:homework??? 注意:如何不使用聚合方法来解决它?例如,通过排序然后更新。
【问题讨论】: