我正在尝试修改文档中的某些字段
{
"_id": 5,
"Applicates": [
{
"School": "UCONN",
"Name": "Mike",
"Research": "cloud computing",
"Budge": 5000,
"appId": 100,
"Time": "5/5/5-6/6/6",
"citizenship": "us",
"Evaluators": [
{
"abstractScore": null,
"goalsObjectivesScore": null,
"evalNum": 1
},
{
"abstractScore": null,
"goalsObjectivesScore": null,
"evalNum": 2
},
{
"abstractScore": null,
"goalsObjectivesScore": null,
"evalNum": 3
}
],
"Major": "csc",
"preAwards": "none",
"Advisor": "Dr. pie"
},
{
"School": "psu",
"Name": "Tom",
"Research": "topology",
"Budge": 7500,
"appId": 101,
"Time": "1/1/1-2/2/2",
"citizenship": "us",
"Evaluators": [
{
"abstractScore": null,
"goalsObjectivesScore": null,
"evalNum": 1
},
{
"abstractScore": null,
"goalsObjectivesScore": null,
"evalNum": 2
},
{
"abstractScore": null,
"goalsObjectivesScore": null,
"evalNum": 3
}
],
"Major": "MAT",
"preAwards": "none",
"Advisor": "Dr. cool"
}
]
}
我需要更新所有空值。我一直试图用$ set在python中做这件事,但没有运气。这就是我的尝试
posts.update({"_id" : 5,"Applicates.Name":"Mike","Application.Evaluators.evalNum":"1"},{"$set":{"Applicates.Evaluators.abstractScore" :10}})
所以我问我如何单独更新每个空字段?我希望上面的代码要做的是更新abstractScore
中的Evaluators中的第一个{"Applicates.Name" : 'Mike"}
。我还要分别更新abstractScore
的其他2 {"Applicates.Name" : 'Mike"}
和{"Applicates.Name" : "Tom"}
的3。当然我也希望goalsObjectivesScore
更新,但我一次尝试做一步。
我环顾四周退出了很多,似乎找不到可靠的答案。任何帮助将不胜感激。
答案 0 :(得分:0)
我与这行代码足够接近。这不完全是我想要的,但我让它能够满足我的需求。
posts.update({"_id":5,"Applicates.appId":100},{"$set":{"Applicates.$.Evaluators.0.abstractScore": 10}})