0
該代碼失敗:最佳的方式來更新嵌套數組在C#/ MongoDB的
public async Task InsertFile(string projectId, string folderId, File file)
{
var project = await Find(projectId);
var folderIndex = project.Folders.IndexOf(project.Folders.Single(x => x.Id == folderId));
var update = Builders<Project>.Update.Push(x => x.Folders[folderIndex].Files, file);
await Collection().UpdateOneAsync(x => x.Id == projectId, update);
}
給出的錯誤是:
Unable to determine the serialization information for x => x.Folders.get_Item(value(Launch.Business.Database.ProjectStore+<>c__DisplayClass3_0).folderIndex).Files.
所以我不能索引對象嵌套數組。
我需要原子更新才能工作。我無法保存整個項目,因爲文件夾更新非常迅速,可能會相互衝突/互相覆蓋。
有了這個約束,什麼是最短和最甜蜜的方式來實現上述?