插入时的 BSON 序列化异常.c#.
本文关键字:异常 序列化 BSON 插入 | 更新日期: 2023-09-27 18:31:57
我有这个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": ""
}
}
Getting MongoDB.Bson.BsonSerializationException in MongoDB.Driver.Core.dll
我该如何调试?
序列化时不得不忽略元数据。 以下作品。
{{
"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 票证。