mongodb - C# class to BSON roundtrip -
i attempting use mongodb store classes habe in application.
the code use
string json = jsonconvert.serializeobject(item); bsondocument document = bsondocument.parse(json); ... await collection.insertoneasync(document);
which seems work fine. when retrieve documents mongodb bsondocument has "_id" attribute added.
how instance of original class (which not have _id attribute)
mongodb automatically adds in object id (_id) attribute serve primary key. happens moment sort of insertion mongodb (no matter if import json, bson, csv, or whatever)
http://docs.mongodb.org/manual/reference/object-id/
if want around issue in c# application, 1 option export mongodb csv, , use tool import csv json, while selectively avoiding _id. seems bit complex unnecessarily though.
perhaps can keep _id attribute , make optional parameter in original c# class? can explain why presence of _id parameter issue begin with?
Comments
Post a Comment