w3resource

MongoDB: db.printCollectionStats() method

db.printCollectionStats

The db.printCollectionStats() method is used to return statistics from every collection separated by three hyphen characters.

Provides a wrapper around the db.collection.stats() method. Returns statistics from every collection separated by three hyphen characters.

Syntax:

db.printCollectionStats()

Note:

The db.printCollectionStats() in the mongo shell does not return JSON. Use db.printCollectionStats() for manual inspection, and db.collection.stats() in scripts.

Example: MongoDB: db.printCollectionStats() method

db.printCollectionStats();

Output:

> db.printCollectionStats();
collection_new
{
        "ns" : "test.collection_new",
        "count" : 0,
        "size" : 0,
        "storageSize" : 5242880,
        "numExtents" : 1,
        "nindexes" : 1,
        "lastExtentSize" : 5242880,
        "paddingFactor" : 1,
        "systemFlags" : 1,
        "userFlags" : 0,
        "totalIndexSize" : 8176,
        "indexSizes" : {
                "_id_" : 8176
        },
        "capped" : true,
        "max" : 5000,
        "ok" : 1
}
---
empdetails
{
        "ns" : "test.empdetails",
        "count" : 4,
        "size" : 960,
        "avgObjSize" : 240,
        "storageSize" : 8192,
        "numExtents" : 1,
        "nindexes" : 1,
        "lastExtentSize" : 8192,
        "paddingFactor" : 1,
        "systemFlags" : 0,
        "userFlags" : 1,
        "totalIndexSize" : 8176,
        "indexSizes" : {
                "_id_" : 8176
        },
        "ok" : 1
}
---
invoice
{
        "ns" : "test.invoice",
        "count" : 1,
        "size" : 112,
        "avgObjSize" : 112,
        "storageSize" : 8192,
        "numExtents" : 1,
        "nindexes" : 1,
        "lastExtentSize" : 8192,
        "paddingFactor" : 1,
        "systemFlags" : 0,
        "userFlags" : 1,
        "totalIndexSize" : 8176,
        "indexSizes" : {
                "_id_" : 8176
        },
        "ok" : 1
}
---
orders
{
        "ns" : "test.orders",
        "count" : 3,
        "size" : 336,
        "avgObjSize" : 112,
        "storageSize" : 8192,
        "numExtents" : 1,
        "nindexes" : 1,
        "lastExtentSize" : 8192,
        "paddingFactor" : 1,
        "systemFlags" : 0,
        "userFlags" : 1,
        "totalIndexSize" : 8176,
        "indexSizes" : {
                "_id_" : 8176
        },
        "ok" : 1
}
---
prod_mast
{
        "ns" : "test.prod_mast",
        "count" : 10,
        "size" : 1120,
        "avgObjSize" : 112,
        "storageSize" : 8192,
        "numExtents" : 1,
        "nindexes" : 4,
        "lastExtentSize" : 8192,
        "paddingFactor" : 1,
        "systemFlags" : 0,
        "userFlags" : 1,
        "totalIndexSize" : 32704,
        "indexSizes" : {
                "_id_" : 8176,
                "item_1_type_1" : 8176,
                "item_1_type_-1" : 8176,
                "cost_1" : 8176
        },
        "ok" : 1
}
---
prod_master
{
        "ns" : "test.prod_master",
        "count" : 10,
        "size" : 1120,
        "avgObjSize" : 112,
        "storageSize" : 8192,
        "numExtents" : 1,
        "nindexes" : 1,
        "lastExtentSize" : 8192,
        "paddingFactor" : 1,
        "systemFlags" : 0,
        "userFlags" : 1,
        "totalIndexSize" : 8176,
        "indexSizes" : {
                "_id_" : 8176
        },
        "ok" : 1
}
---
restaurants
{
        "ns" : "test.restaurants",
        "count" : 25359,
        "size" : 14721552,
        "avgObjSize" : 580,
        "storageSize" : 22507520,
        "numExtents" : 7,
        "nindexes" : 1,
        "lastExtentSize" : 11325440,
        "paddingFactor" : 1,
        "systemFlags" : 0,
        "userFlags" : 1,
        "totalIndexSize" : 752192,
        "indexSizes" : {
                "_id_" : 752192
        },
        "ok" : 1
}
---
restaurants_new
{
        "ns" : "test.restaurants_new",
        "count" : 25359,
        "size" : 14721552,
        "avgObjSize" : 580,
        "storageSize" : 22507520,
        "numExtents" : 7,
        "nindexes" : 2,
        "lastExtentSize" : 11325440,
        "paddingFactor" : 1,
        "systemFlags" : 0,
        "userFlags" : 1,
        "totalIndexSize" : 1504384,
        "indexSizes" : {
                "_id_" : 752192,
                "cuisine_1" : 752192
        },
        "ok" : 1
}
---
system.indexes
{
        "ns" : "test.system.indexes",
        "count" : 13,
        "size" : 1456,
        "avgObjSize" : 112,
        "storageSize" : 8192,
        "numExtents" : 1,
        "nindexes" : 0,
        "lastExtentSize" : 8192,
        "paddingFactor" : 1,
        "systemFlags" : 0,
        "userFlags" : 1,
        "totalIndexSize" : 0,
        "indexSizes" : {

        },
        "ok" : 1
}
---
system.profile
{
        "ns" : "test.system.profile",
        "count" : 12,
        "size" : 6988,
        "avgObjSize" : 582,
        "storageSize" : 1048576,
        "numExtents" : 1,
        "nindexes" : 0,
        "lastExtentSize" : 1048576,
        "paddingFactor" : 1,
        "systemFlags" : 0,
        "userFlags" : 0,
        "totalIndexSize" : 0,
        "indexSizes" : {

        },
        "capped" : true,
        "max" : NumberLong("9223372036854775807"),
        "ok" : 1
}
---
userdetails
{
        "ns" : "test.userdetails",
        "count" : 1,
        "size" : 496,
        "avgObjSize" : 496,
        "storageSize" : 8192,
        "numExtents" : 1,
        "nindexes" : 1,
        "lastExtentSize" : 8192,
        "paddingFactor" : 1,
        "systemFlags" : 0,
        "userFlags" : 1,
        "totalIndexSize" : 8176,
        "indexSizes" : {
                "_id_" : 8176
        },
        "ok" : 1
}
---

Retrieve the restaurants data from here

Previous: db.logout() method
Next: db.repairDatabase() method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/mongodb/shell-methods/database/db-printCollectionStats.php