Reputation: 1654
I'm trying to monitor mongoServer including running process and its during time.
Is there any way to get db.currentOp() in C# ?
Upvotes: 1
Views: 1006
Reputation: 930
Using the 2.0 driver:
MongoClient client = new MongoClient("mongodb://localhost");
var db = client.GetDatabase("test");
var collection = db.GetCollection<BsonDocument>("$cmd.sys.inprog");
var currentOp = collection.Find(new BsonDocument()).FirstOrDefault();
After updating our MongoDB instance to 3.4.10 (from 3.0), the previous answer no longer worked for me. Here's what I had to update it to:
MongoClient client = new MongoClient("mongodb://root:password@localhost?authSource=admin");
var db = client.GetDatabase("admin");
var command = new BsonDocument {
{ "currentOp", "1"},
};
var currentOp = db.RunCommand<BsonDocument>(command);
Upvotes: 2
Reputation: 46341
Google could probably answer this question... How about GetCurrentOp
?
MongoClient client = new MongoClient("mongodb://localhost");
var server = client.GetServer();
var db = server.GetDatabase("test", WriteConcern.Acknowledged);
var currentOp = db.GetCurrentOp();
Upvotes: 2