c# 4.0 - not able to save documents in mongodb c# with .Net driver 2.0 -
i want save document in collection method below not saving @ all.
internal static void initializedb() { var db = getconnection(); var collection = db.getcollection<bsondocument>("locations"); var locations = new list<bsondocument>(); var json = jobject.parse(file.readalltext(@"..\..\test_files\testdata.json")); foreach (var d in json["locations"]) { using (var jsonreader = new jsonreader(d.tostring())) { var context = bsondeserializationcontext.createroot(jsonreader); var document = collection.documentserializer.deserialize(context); locations.add(document); } } collection.insertmanyasync(locations); }
if made async , await runs lately, need run first , test data.
for future reference, wait()
@ end of async method work synchronously
internal static void initializedb() { var db = getconnection(); var collection = db.getcollection<bsondocument>("locations"); var locations = new list<bsondocument>(); var json = jobject.parse(file.readalltext(@"..\..\test_files\testdata.json")); foreach (var d in json["locations"]) { using (var jsonreader = new jsonreader(d.tostring())) { var context = bsondeserializationcontext.createroot(jsonreader); var document = collection.documentserializer.deserialize(context); locations.add(document); } } collection.insertmanyasync(locations).wait(); }
Comments
Post a Comment