您如何设定治疗,喜欢或疾病等价值? 我尝试过
db.myCollection.update({first_name:"QQQ"},{$unset:{"history.treatment":1}});
找到匹配项,但不会取消设置。我在做什么错了?
myCollection:
{ first_name: "QQQ",
last_name: "BBBB",
"history" : [
{
"disease" : [
"X",
"Y",
"Z"
],
"treatment" : "No treatment",
"likes" : "french fries"
}
]}
答案 0 :(得分:1)
Treatement
嵌套在history array
内,因此您需要使用$[]位置运算符
db.myCollection.update({first_name:"QQQ"},{$unset:{"history.$[].treatment":1}});