get collection stats in C++

34 views
Skip to first unread message

Mick

unread,
Oct 1, 2012, 6:32:09 PM10/1/12
to mongod...@googlegroups.com
Hi there,
I know there is a way to get database stats in C++, like so:
 

bsonQry = BSON("dbStats" << 1 << "scale" << 1);

conn->runCommand( dbName, bsonQry, bsonResult);

I'm wondering if there is a way to get stats about a collection - I basically need the count, size, avgObjSize and storageSize.

Thank you in advance.

David Hows

unread,
Oct 1, 2012, 11:37:41 PM10/1/12
to mongod...@googlegroups.com
You should be able to use the colStats command in the same manner, ie:

    BSONObj bsonQry = BSON("collStats" << "bar");
    c.runCommand( "test", bsonQry, ret);
    std::cout << ret << std::endl;

Output:
    { ns: "test.bar", count: 3, size: 416, avgObjSize: 138.6666666666667, storageSize: 12288, numExtents: 1, nindexes: 1, lastExtentSize: 12288, paddingFactor: 1.0, systemFlags: 1, userFlags: 0, totalIndexSize: 8176, indexSizes: { _id_: 8176 }, ok: 1.0 }



Mick

unread,
Oct 2, 2012, 11:35:09 AM10/2/12
to mongod...@googlegroups.com
Thank you very much, David :)  That's exactly what I needed.
Reply all
Reply to author
Forward
0 new messages