簡體   English   中英

插入時發生BSON序列化異常。 C#

[英]BSON Serialization Exception on insert. c#

我有這個BsonDocument,我正嘗試用insertOneAsync插入:

{{
    "starttime": "05.11.2003 17:29:35.189",
    "clk": "0.01",
    "frames": "000001328",
    "typ": "real",
    "MasterRev": "19",
    "WriterVer": "3.0.85",
    "ClientKey": "B4B18CC22F9A4F82FA4D975B53933B5A",
    "Start": "11/05/2003 17:29:35",
    "ID": "File2",
    "InfoCustomEntryA": "AAA0",
    "InfoCustomEntryB": "B1",
    "InfoCustomEntryC": "Just A Standard Entry For The Cold Mill",
    "module_name_0": "RealSignals",
    "module_name_1": "RealSignals5x",
    "module_name_2": "IntegerSignals",
    "module_name_3": "IntegerSignals6x",
    "ibaFilesTest": "12/4/2015 11:46:10 AM",
    "ibaFiles": "6.3.2 Lite (update)",
    "$DATCOOR_status": "processed",
    "$DATCOOR_OutputFiles": "",
    "$DATCOOR_times_tried": "1",
    "$DATCOOR_TasksDone": ""
}
}

在MongoDB.Driver.Core.dll中獲取MongoDB.Bson.BsonSerializationException

我該如何調試?

我序列化時不得不忽略元數據。 以下作品。

{{
    "starttime": "05.11.2003 17:29:35.189",
    "clk": "0.01",
    "frames": "000001328",
    "typ": "real",
    "MasterRev": "19",
    "WriterVer": "3.0.85",
    "ClientKey": "B4B18CC22F9A4F82FA4D975B53933B5A",
    "Start": "11/05/2003 17:29:35",
    "ID": "File2",
    "InfoCustomEntryA": "AAA0",
    "InfoCustomEntryB": "B1",
    "InfoCustomEntryC": "Just A Standard Entry For The Cold Mill",
    "module_name_0": "RealSignals",
    "module_name_1": "RealSignals5x",
    "module_name_2": "IntegerSignals",
    "module_name_3": "IntegerSignals6x",
    "ibaFilesTest": "12/4/2015 11:46:10 AM",
    "ibaFiles": "6.3.2 Lite (update)"
}
}

我該如何調試?

嘗試在對InsertOneAsync的調用周圍放置try-catch塊,如下所示:

try
{
    YourMongoCollectionHere.InsertOneAsync(YourBsonDocumentHere);
}
catch (MongoException e)
{
    // examine your exception 'e' here
}

您需要刪除多余的花括號以獲取有效的JSON,但是,更重要的是Mongo不允許以$開頭的字段名稱,請參見JIRA票證。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM