MongoDB – get data size and index size

MongoDB


when you logged-in in mongos console and run the db.stats() command you can find with all values as 0 (Zero) , it means you have not selected any database. First select database using following

1
> use orderDB;

1. Overview of db.stats() command

Here are the details of db.stats() command. which are helpful to understand you what are the paremeter you get and what are the meaning of those parameters.

key details
db this is name of the database which you have selected.
collections number of collection in selected (orderDB) database.
objects self descriptive
avgObjSize self descriptive , average size of the object in this databse
dataSize size of the data in bytes/KB/MB/GB, based upone the factor provided (i.e 1024)
storageSize size of the index in bytes/KB/MB/GB, based upone the factor provided (i.e 1024)
indexSize size of the index in bytes/KB/MB/GB, based upone the factor provided (i.e 1024)
indexes self descriptive , no of index in this database (i.e. orderDB)
fileSize self descriptive, size of the file which hold select database
ok the value of 1 means , command runs successfully if 0 then something went wrong.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[ranjeet@ranjeetJha ~]$ mongo
MongoDB shell version: 3.0.14
connecting to: test
rs1:SECONDARY> db.stats();
{
        "db" : "test",
        "collections" : 0,
        "objects" : 0,
        "avgObjSize" : 0,
        "dataSize" : 0,
        "storageSize" : 0,
        "numExtents" : 0,
        "indexes" : 0,
        "indexSize" : 0,
        "fileSize" : 0,
        "ok" : 1
}

2. Get data size and index size in bytes

In the following command dataSize and storageSize are in bytes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
rs1:SECONDARY> use orderDB
switched to db orderDB
rs1:SECONDARY> db.stats();
{
        "db" : "orderDB",
        "collections" : 153,
        "objects" : 62895870,
        "avgObjSize" : 3773.4611682452282,
        "dataSize" : 237335123088,
        "storageSize" : 46984601600,
        "numExtents" : 0,
        "indexes" : 248,
        "indexSize" : 1938391040,
        "ok" : 1
}

3. Get data size and index size in Kilobytes (KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
rs1:SECONDARY> db.stats(1024);
{
        "db" : "orderDB",
        "collections" : 153,
        "objects" : 62895964,
        "avgObjSize" : 3773.464072877554,
        "dataSize" : 231773105.9404297,
        "storageSize" : 45883408,
        "numExtents" : 0,
        "indexes" : 248,
        "indexSize" : 1892960,
        "ok" : 1
}

4. Get data size and index size in MB (Megabytes)

1
2
3
4
5
6
7
8
9
10
11
12
13
rs1:SECONDARY> db.stats(1024*1024);
{
        "db" : "orderDB",
        "collections" : 153,
        "objects" : 62896034,
        "avgObjSize" : 3773.469466532659,
        "dataSize" : 226341.49919986725,
        "storageSize" : 44808.03515625,
        "numExtents" : 0,
        "indexes" : 248,
        "indexSize" : 1848.609375,
        "ok" : 1
}

5. Get data size and index size in GB (Gigabytes)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
rs1:SECONDARY> db.stats(1024*1024*1024);
{
        "db" : "orderDB",
        "collections" : 153,
        "objects" : 62896116,
        "avgObjSize" : 3773.4681172999617,
        "dataSize" : 221.03682945296168,
        "storageSize" : 43.75809097290039,
        "numExtents" : 0,
        "indexes" : 248,
        "indexSize" : 1.8053054809570312,
        "ok" : 1
}
 
rs1:SECONDARY>

Your comments are welcome to improve this post, you have learned , how to get size of index and data from a particular database in mongodb. Happy learning.

Please follow and like us:
RSS
Follow by Email
Facebook
LinkedIn
Google+

Leave a Reply

Your email address will not be published. Required fields are marked *