Details
-
Task
-
Resolution: Done
-
Major - P3
-
None
-
1.10.1
-
Windows,
Mongo:
/* 1 */
{
"version" : "3.2.0",
"gitVersion" : "45d947729a0315accb6d4f15a6b06be6d9c19fe7",
"targetMinOS" : "Windows 7/Windows Server 2008 R2",
"modules" : [],
"allocator" : "tcmalloc",
"javascriptEngine" : "mozjs",
"sysInfo" : "deprecated",
"versionArray" : [
3,
2,
0,
0
],
"openssl" : {
"running" : "OpenSSL 1.0.1p-fips 9 Jul 2015",
"compiled" : "OpenSSL 1.0.1p-fips 9 Jul 2015"
},
"buildEnvironment" : {
"distmod" : "2008plus-ssl",
"distarch" : "x86_64",
"cc" : "cl: Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64",
"ccflags" : "/nologo /EHsc /W3 /wd4355 /wd4800 /wd4267 /wd4244 /wd4290 /wd4068 /wd4351 /we4013 /we4099 /we4930 /Z7 /errorReport:none /MD /O2 /Oy- /Gw /Gy /Zc:inline",
"cxx" : "cl: Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64",
"cxxflags" : "/TP",
"linkflags" : "/nologo /DEBUG /INCREMENTAL:NO /LARGEADDRESSAWARE /OPT:REF",
"target_arch" : "x86_64",
"target_os" : "windows"
},
"bits" : 64,
"debug" : false,
"maxBsonObjectSize" : 1.67772e+007,
"storageEngines" : [
"devnull",
"ephemeralForTest",
"mmapv1",
"wiredTiger"
],
"ok" : 1.0000000000000000
}Windows, Mongo: /* 1 */ { "version" : "3.2.0", "gitVersion" : "45d947729a0315accb6d4f15a6b06be6d9c19fe7", "targetMinOS" : "Windows 7/Windows Server 2008 R2", "modules" : [], "allocator" : "tcmalloc", "javascriptEngine" : "mozjs", "sysInfo" : "deprecated", "versionArray" : [ 3, 2, 0, 0 ], "openssl" : { "running" : "OpenSSL 1.0.1p-fips 9 Jul 2015", "compiled" : "OpenSSL 1.0.1p-fips 9 Jul 2015" }, "buildEnvironment" : { "distmod" : "2008plus-ssl", "distarch" : "x86_64", "cc" : "cl: Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64", "ccflags" : "/nologo /EHsc /W3 /wd4355 /wd4800 /wd4267 /wd4244 /wd4290 /wd4068 /wd4351 /we4013 /we4099 /we4930 /Z7 /errorReport:none /MD /O2 /Oy- /Gw /Gy /Zc:inline", "cxx" : "cl: Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64", "cxxflags" : "/TP", "linkflags" : "/nologo /DEBUG /INCREMENTAL:NO /LARGEADDRESSAWARE /OPT:REF", "target_arch" : "x86_64", "target_os" : "windows" }, "bits" : 64, "debug" : false, "maxBsonObjectSize" : 1.67772e+007, "storageEngines" : [ "devnull", "ephemeralForTest", "mmapv1", "wiredTiger" ], "ok" : 1.0000000000000000 }
Description
I am using Mongo C# driver to query data. Executing command from shell/robomongo seems easy to use but trying to execute same command from C# seems little difficult.
e.g. In Shell, I am executing following command:
db.runCommand(
{
"find":"Equity",
"filter":
}
)
Same command is C# driver as follow:
var client = new MongoClient();
var database = client.GetServer().GetDatabase("MONGOXDB");
Dictionary<string, object> dictionary = new Dictionary<string, object>();
dictionary.Add("find", "Equity");
BsonElement bElement1 = new BsonElement("Ticker", "AAPL US Equity");
BsonElement bElement2 = new BsonElement("Ask"(BsonValue)101.2600000000000100);
dictionary.Add("filter", new BsonDocument
{ bElement1, bElement2 });
var command = new CommandDocument
{ dictionary };
CommandResult result = database.RunCommand(command);
BsonDocument bdocument = result.Response;
---------------------------------------
Now question is there way of passing Mongo query as string in C# and then get result back.