我的文档中有一个数组,我想更新,但到目前为止我没有解决它。这里doctor
是集合的名称,它不是一个对象。
doctor: {
_id = ObjectID(571fb65678fcd63c29db423a),
appointmentList : [
{patientID:"123", date: "25 MARCH"},
{patientID:"456", date: "26 MARCH"},
{patientID:"789", date: "27 MARCH"},
{patientID:"101112", date: "28 MARCH"}
]
}
在这种情况下,我想更新 patientID =“123”的日期。为此我创建了这个查询,但这不起作用
db.collection.update(
{
"_id" : ObjectId("571fb65678fcd63c29db423a"),
"appointmentList.patientID": "123"
},
{
"$set": {
"appointmentList.$.date" : "XXXXX"
}
}
);
输出:
> db.collection.update(
{
"_id" : ObjectId("571fb65678fcd63c29db423a"),
"appointmentList.patientID": "123"
},
{
"$set": {
"appointmentList.$.date" : "XXXXX"
}
}
);
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })
最好的问候
答案 0 :(得分:-1)
试试这个:
> db.collection.update(
{
"_id" : "571fb65678fcd63c29db423a",
"appointmentList.patientID": "123"
},
{
"$set": {
"appointmentList.$.date" : "XXXXX"
}
}
);