How to call db.Collection.stats() from Mongo java driver

前端 未结 3 1465
执念已碎
执念已碎 2020-12-19 15:31


From Mongodb client, we can use db.Collection.stats() to get status of collections, such as:
+ Number of records (count)
+ Size on disk (storageSize)

3条回答
  •  天命终不由人
    2020-12-19 15:58

    This will work:

    CommandResult resultSet = db.getCollection("emp").getStats();
            System.out.println(resultSet);
    

    you will get all the details of status.ouput:

    { "ns" : "test.emp" , "count" : 2 , "size" : 96 , "avgObjSize" : 48 , "numExtents" : 1 , "storageSize" : 8192 , "lastExtentSize" : 8192.0 , "paddingFactor" : 1.0 , "paddingFactorNote" : "paddingFactor is unused and unmaintained in 3.0. It remains hard coded to 1.0 for compatibility only." , "userFlags" : 1 , "capped" : false , "nindexes" : 1 , "indexDetails" : { } , "totalIndexSize" : 8176 , "indexSizes" : { "_id_" : 8176} , "ok" : 1.0}
    

提交回复
热议问题