简体   繁体   English

插入时发生BSON序列化异常。 C#

[英]BSON Serialization Exception on insert. c#

i have this BsonDocument that i'm trying to insert with insertOneAsync : 我有这个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 在MongoDB.Driver.Core.dll中获取MongoDB.Bson.BsonSerializationException

How can I debug this? 我该如何调试?

Had to ignore the meta data when i serialized. 我序列化时不得不忽略元数据。 The following works. 以下作品。

{{
    "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)"
}
}

How can I debug this? 我该如何调试?

Try placing a try-catch block around your call to InsertOneAsync , like so: 尝试在对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