Jason
Jason

Reputation: 349

BSON Serialization Exception on insert. c#

i have this BsonDocument that i'm trying to insert with 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

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

Upvotes: 0

Views: 1231

Answers (2)

Chase
Chase

Reputation: 944

How can I debug this?

Try placing a try-catch block around your call to InsertOneAsync, like so:

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

Upvotes: 1

Alex
Alex

Reputation: 21766

You need to remove the extra curly brackets to get valid JSON, however, more importantly Mongo doesn't allow field names that start with $, see this JIRA ticket.

Upvotes: 0

Related Questions