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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -