我的收藏中有一份文件,如下所示。我想更新特定的对象值。请解决这个问题。如何更新isChecked : "0"
{
"STUDENT_001": {
"name": "name1",
"hobbies": {
"01": {
"isChecked": "1",
"name": "hobby - name"
},
"02": {
"isChecked": "0",
"name": "hobby-name"
}
}
},
"STUDENT_002": {
"name": "name2",
"hobbies": {
"01": {
"isChecked": "1",
"name": "hobby - name"
},
"02": {
"isChecked": "1",
"name": "hobby-name"
}
}
}
}
答案 0 :(得分:0)
应该是这样的:
.update(
query,
new BasicDBObject(
"$set",
new BasicDBObject("STUDENT_001.hobbies.01.isChecked", "0")
));
这里查询匹配文档。并且$set
更新指定路径中的字段,即"STUDENT_001.hobbies.01.isChecked"