no, the best you can do in this context is to use db.RunCommand<BsonDocument>("{ ping : 1 }")
(c#) which is close to the shell db.runCommand({ ping : 1 })
UPDATE:
you may look at this as well How to execute mongo commands through shell scripts?, I'm not familiar with this and it doesn't work for me on windows and 5.0 server in most of the cases mentioned there other than simple one: mongo --eval "printjson(db.serverStatus())"
, but if you will be able to make this suggested script mongo < script.js
(or similar) work in, for example, the shell, you will be able to put your random query in this file(script.js
) and then, add this file as argument into Process creating similar to:
using (var process = new Process())
{
// arguments below may require the whole path to the files
process.StartInfo.Arguments = "script.js";
process.StartInfo.FileName = "mongo";
process.Start();
}
to read results, you will need analyzing process.StandardOutput
/process.StandardError
stream.