我有一个包含一系列文档的产品文档.例如
{
id: 1,
name: "J-E-L-L-O",
store:[{id: 1,
name: "Store X"},
{id: 2,
name: "Store Y"}]
}
Run Code Online (Sandbox Code Playgroud)
我想将"Store Y"的名称更改为"Store Z",例如.当时,我不知道对象的索引.所以,我拉出整个数组,找到要更新的对象,更改名称,然后尝试使用更新的数组设置"store"的值.
productCollection.Update(query, Update.Set("store", storeList.ToBsonDocument()));
Run Code Online (Sandbox Code Playgroud)
但是,我收到一个错误: "An Array value cannot be written to the root level of a BSON document."
我想我只需要知道如何将自定义对象数组序列化为BsonDocuments数组.
在此先感谢您的帮助.