我正在将NODE-js与猫鼬一起使用。当我尝试使用子文档更新具有数组属性的文档时,将从文档中删除没有值的子文档键。 如何在不删除子文档字段的情况下进行更新
更新前的文档:
{
"Code": 0,
"Data": {
"_id": "5cd11d8edc462b23fc1557a9",
"Teams": [
{
"_id": "5cd11d8edc462b23fc1557ac",
"GameState": 2,
"Name" : "test
}
],
"Name": "Name"
},
"Message": ""
}
更新json:
{
"_id" : "5cd11d8edc462b23fc1557a9",
"Teams" : [
{
"_id" :"5cd11d8edc462b23fc1557ac",
"GameState" : 2
}
]
}
更新后的文档:
{
"Code": 0,
"Data": {
"_id": "5cd11d8edc462b23fc1557a9",
"Teams": [
{
"_id": "5cd11d8edc462b23fc1557ac",
"GameState": 2
}
],
"Name": "Name"
},
"Message": ""
}
更新文档:
let group = await Group.findOneAndUpdate({_id : req.body._id},{ $set: req.body},{ new: true });