我试图删除存储在mongoDB文档中的部分数据(见下面的示例),我想删除所有“任务变量”(它不是一个数组)的数据,一些文档包含数千个。
数据:
{
"Id": "1",
"referenceId": "A001",
"createdAt": "2023-04-25T11:08:06.384Z",
"data": {
"errors": {
"archive": {
"data": {
"A1": {
"name": "Error",
"stamp": "2023-04-25T11:08:10.700Z",
"task-variables": {
"taskErrorMessage": null,
"nrOfActiveInstances": 1,
"errorCode": "error-archiving"
}
},
"A2": {
"name": "Error",
"stamp": "2023-04-25T11:08:10.700Z",
"task-variables": {
"taskErrorMessage": null,
"nrOfActiveInstances": 1,
"errorCode": "error-archiving"
}
}
}
}
}
}
}
我尝试了下面的例子,但它不起作用。如何删除/删除它?
db.getCollection("my-collection").updateOne(
{ referenceId: "A001" },
{ $unset: { "data.errors.archive.data.$**.task-variables": "" } }
)
1条答案
按热度按时间t9aqgxwy1#