我有这个
{
"ClockID" : "fd51b6e0-5b81-49ab-8424-71fd768281b2",
"ClockName" : "AAA-TEST123-002",
"FilesList" : [{
"FileName" : "AAA-TEST123-002.mpg",
"FileLocationHistory" : [{
"FullPath" : "192.168.32.166/Ingestion",
"AllowDeleteOnCancel" : false,
"_id" : "565b7343-9dc5-4916-a788-0f392fce2502"
}],
"_id" : "15b54499-a0be-4278-82ed-58c82c13bd40",
}],
"_id" : ObjectId("510164d0a63cfa2250fd6d19"),
"_t" : "ClockRecord"
当我用这个更新 FileLocationHistory 数组文档时:
public void UpdateClockFilesLocationRecord(string collectionName, ClockFileLocationHistoryRecord clockFileLocationHistory, BsonObjectId clockDocumentID, string clockFileDocumentID)
{
var mongoCollection = MongoDatabase.GetCollection<ClockRecord>("Clocks");
var update = Update.Set("FilesList.$.FileLocationHistory", BsonDocumentWrapper.Create<ClockFileLocationHistoryRecord>(clockFileLocationHistory));
var modeResult = mongoCollection.Update(
Query.And(
Query.EQ("_id", clockDocumentID),
Query.EQ("FilesList._id", clockFileDocumentID)
),
update, UpdateFlags.Upsert
);
}
更新通过,但文档不再是数组:
{
"ClockID" : "fd51b6e0-5b81-49ab-8424-71fd768281b2",
"ClockName" : "AAA-TEST123-002",
"FilesList" : [{
"FileName" : "AAA-TEST123-002.mpg",
"FileLocationHistory" : {
"FullPath" : "192.168.32.166/Ingestion",
"AllowDeleteOnCancel" : false,
"_id" : "565b7343-9dc5-4916-a788-0f392fce2502"
},
"_id" : "15b54499-a0be-4278-82ed-58c82c13bd40",
}],
"_id" : ObjectId("510164d0a63cfa2250fd6d19"),
"_t" : "ClockRecord"
这意味着该文档尝试将其反序列化为驱动程序无法识别的对象。
我的更新代码有什么问题?