0
如果我有一個包含數組的數組的文檔,如何更新第二個數組的字段?mongodb c#在數組中設置數組值
例如,使用MongoDB的C#的驅動程序,我想更新的領域IWantToUpdateThis其中值是約翰·史密斯:
{
{
"_id" : 0,
"Guff" : "Blah",
"FirstArray" : [
{
"Blah" : "Guff",
"SecondArray" : [
{
"IWantToUpdateThis" : "John Smith",
"ButNotThis" : "Not me"
},
{
"IWantToUpdateThis" : "Will Smith",
"ButNotThis" : "Not me"
}
]
}
]
} }
我嘗試了各種選項,例如:
var filter = Builders<BsonDocument>.Filter.Eq("FirstArray.SecondArray.IWantToUpdateThis", "John Smith");
var update = Builders<BsonDocument>.Update.Set("FirstArray.SecondArray.$.IWantToUpdateThis", "My New Value");
var result = collection.UpdateOne(filter, update);
但我似乎無法更新價值。
編輯補充: 當問題被提出使用MongoDB的版本是v3.2.12-69-g45cc6d2