MongoDB更新注意事项
如果一个字段同时被多个更新操作符更新会报错
Updating the path '*' would create a conflict at '*'
举个栗子:
//原文档
{
"_id": ObjectId("6018e5dfeb2e0000ee004aea"),
"name": "lillian",
"contacts": [
[
1,
2
],
"222"
]
}
//更新语句
db.account.updateOne({name:"lillian"},{$push:{contacts:"333"},$set:{"contacts.0":[1,2,3]}});
//就会提示错误
[Error] index 0: 40 - Updating the path 'contacts.0' would create a conflict at 'contacts'
at line 1, column 1