1
這裏的比賽是我的MongoDB文檔MongoDB的更新嵌套數組對象,其中有數組文件
{
"_id":20,
"GroupId":"45",
"Name":"Some Name",
"NestedArray":[
{
"Id":3,
"Name":"NesName",
"IsDeleted":false
}
]
}
我需要寫一個更新語句一樣(在SQL解釋)
update MyCollections.NestedArray set MyCollections.NestedArray[x].IsDeleted = true where MyCollections.NestedArray[x].Id = 3
這裏我用MongoDB 3.2
我怎麼能拿出一個MongoDB的C#驅動程序查詢試圖
var groupFilter = Builders<MyType>.Filter.Eq(x => x.Id, 45);
var nestedArayDocUpdate = Builders<MyType>.Update.Set(x => x.NestedArray[0].IsDeleted, true);
mongoDbRepository.UpdateMany(groupFilter, nestedArayDocUpdate,
new UpdateOptions {IsUpsert = false, BypassDocumentValidation = false});
?