Get database data size in MongoDB?


To get the database data size in MongoDB, you can use stats() method. The syntax is as follows −

db.stats();

Let us use the database with the name ‘test’.

Now, check the current database with the help of the following query −

> db;

The following is the output −

test

Here is the query to get database data size in MongoDB −

> db.stats()

The following is the output −

{
   "db" : "test",
   "collections" : 114,
   "views" : 0,
   "objects" : 391,
   "avgObjSize" : 83.0076726342711,
   "dataSize" : 32456,
   "storageSize" : 3211264,
   "numExtents" : 0,
   "indexes" : 120,
   "indexSize" : 2494464,
   "fsUsedSize" : 126172377088,
   "fsTotalSize" : 199229435904,
   "ok" : 1
}

Switch to the database ‘sample’. The query is as follows −

> use sample;
switched to db sample

Let us check the currently used database name using db command. The query is as follows −

> db;

The following is the output −

Sample

Let us check the database ‘sample’ data size in MongoDB. The query is as follows −

> db.stats();

The following is the output −

{
   "db" : "sample",
   "collections" : 25,
   "views" : 0,
   "objects" : 67,
   "avgObjSize" : 85.32835820895522,
   "dataSize" : 5717,
   "storageSize" : 626688,
   "numExtents" : 0,
   "indexes" : 24,
   "indexSize" : 610304,
   "fsUsedSize" : 126173016064,
   "fsTotalSize" : 199229435904,
   "ok" : 1
}

Updated on: 30-Jul-2019

708 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements