[CSHARP-1930] What is the alternative for 'Database.GetStats()' in MongoDB.Driver 2.4.2? Created: 03/Mar/17  Updated: 27/Oct/23  Resolved: 03/Mar/17

Status: Closed
Project: C# Driver
Component/s: API, Documentation
Affects Version/s: 2.4.2
Fix Version/s: None

Type: Task Priority: Blocker - P1
Reporter: Ummer Irshad Assignee: Robert Stam
Resolution: Works as Designed Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS : Win 7
.Net 4.6.1



 Description   

In MongoCsharpdriver 1.11.0, Database.GetStats() is available for getting the state of server.
What is the alternative for the same in MongoDB Driver 2.4.2.

I have tried with ServerDescription object, but it is always returning as disconnected .During this time,I am able to access collections using the driver.

Thanks in advance.



 Comments   
Comment by Robert Stam [ 08/Mar/17 ]

The timeout question was moved to a new ticket: CSHARP-1934.

Comment by Ummer Irshad [ 08/Mar/17 ]

Dear Robert Stam,

Is there any way to reduce the default command timeout of 30000ms of RunCommand in below code?

var command = new BsonDocument { { "dbstats", 1 } };
var stats = database.RunCommand<BsonDocument>(command);
Console.WriteLine(stats.ToJson()); // do something with the stats

Thanks in advance.
Irshad.

Comment by Robert Stam [ 06/Mar/17 ]

You're welcome.

Comment by Ummer Irshad [ 06/Mar/17 ]

Thank you very much @Robert Stam for a quick reply.

Comment by Robert Stam [ 03/Mar/17 ]

Drivers in general have moved away from providing very specific helper methods like GetStats for two reasons:

1. Few applications actually need them
2. The results returned from the server vary from version to version of the server

But you can easily run the underlying dbstats command yourself. The dbstats command is documented here:

https://docs.mongodb.com/manual/reference/command/dbStats/

And your code would look like this:

var command = new BsonDocument { { "dbstats", 1 } };
var stats = database.RunCommand<BsonDocument>(command);
Console.WriteLine(stats.ToJson()); // do something with the stats

Generated at Wed Feb 07 21:41:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.