【发布时间】:2017-12-28 15:16:17
【问题描述】:
我在 MongoDB 中有一个类似这样的文档:
{
"Id":"123",
"Product": "test",
"Tags":[
{
"Name": "name",
"Categories": [
{
//item
},
{
//item
}
]
},
{
"Name": "name",
"Categories": [
{
//item
},
{
//item
}
]
}
]
}
现在,我需要添加一个新的Item,它需要通过其Id 添加到该Product 的Tags 元素的所有类别中。
例如,当我插入 Item 3 时,文档应如下所示:
{
"Id":"123",
"Product": "test",
"Tags":[
{
"Name": "name",
"Categories": [
{
//item 1
},
{
//item 2
},
{
//item 3
}
]
},
{
"Name": "name",
"Categories": [
{
//item 1
},
{
//item 2
},
{
//item 3
}
]
}
]
}
删除一个项目也是如此,它也需要从所有类别中删除。 有没有办法用 C# MongoDB 驱动程序做到这一点,而无需拉取对象并“手动”更新它们?
【问题讨论】:
标签: c# mongodb mongodb-.net-driver