How to get ths statistics from MongoCollection class

107 views
Skip to first unread message

ml.ve...@gmail.com

unread,
Sep 16, 2016, 1:34:10 PM9/16/16
to mongodb-user
Hi all,

Am using java driver v 3.2 to connect to the MongoDB 3.2 . Am looking for ways to print the statistics of the collection from my java program.

In DBCollection, we have a method getStats() which does the job of getting all the statistics

But in V 3.2 , the direction is to use MongoCollection and am not sure how to print the Collection statistics


In the shell , yes I can use db.<collection>.stats() to print the collection . Not sure how to do it via MongoCollection class


Thanks
Venkat

Wan Bachtiar

unread,
Sep 21, 2016, 3:49:05 AM9/21/16
to mongodb-user

Am looking for ways to print the statistics of the collection from my java program.

Hi Venkat,

You could utilise the runCommand() to retrieve collection stats, for example using MongoDB Java Driver v3.2:

MongoDatabase database = client.getDatabase("databaseName");
Document stats = database.runCommand(new Document("collStats", "collectionName"));
System.out.println(stats);

For more info see MongoDB Java Driver v3.2: running a command.

Regards,

Wan

Reply all
Reply to author
Forward
0 new messages