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

前端 未结 3 1481
执念已碎
执念已碎 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:46

    Use CommandResult to finding collection stat in java check below code :

    Mongo mongo = new Mongo("localhost", 27017);
    DB db = mongo.getDB("data base name");
    CommandResult resultSet = db.getCollection("collectionName").getStats();
    System.out.println(resultSet);
    System.out.println(resultSet.get("count"));
    System.out.println(resultSet.get("avgObjSize"))
    

提交回复
热议问题