Is it possible to get the data type of mongodb collection fields using c#? -


i need create datatable stores result of mongodb query using correct data type of fields (string ,double...). here code using here specifying type of created column string type need find way correct type of field:

        var connectionstring = "mongodb://localhost";         var client = new mongoclient(connectionstring);         var server = client.getserver();         var database = server.getdatabase("test");         var collection = database.getcollection("doc1");          datatable dt;         datacolumn column;         int = 0;          dt = new datatable();         string map = @"function() {     (var key in this) { emit(key, null); }    }";         string reduce = @"function(key, stuff) { return null; }";         string finalize = @"function(key, value){        return key;    }";         mapreduceargs args = new mapreduceargs();         args.finalizefunction = new bsonjavascript(finalize);         args.mapfunction = new bsonjavascript(map);         args.reducefunction = new bsonjavascript(reduce);         var results = collection.mapreduce(args);         list<string> fields = new list<string>();         foreach (bsonvalue result in results.getresults().select(item => item["_id"]))         {             fields.add(result.asstring);         }           foreach (string p in fields)         {// here need add correct type of field not string type             column = new datacolumn(p, type.gettype("system.string"));             dt.columns.add(column);             i++;         } 


Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

java - Could not locate OpenAL library -

Non Unique Username with ASP.Net Identity 2.0 -