How to Check MongoDB Size in GB: 4 Easy Steps

Feature image of mongodb database size
As a DBA when managing a MongoDB instance, monitoring database size is crucial for performance optimization and storage planning. This guide will help you to check MongoDB size in GB. Let’s go through this:

Why Checking the size of MongoDB is Important

Regularly checking the size of MongoDB helps on below:

Monitor Storage Growth – Prevent unexpected storage issues.
Optimize Performance – Reduce query response times.
Improve Backup & Maintenance – Manage disk space efficiently.

Login to Mongo Shell:

mongo

Login to the Desired MongoDB to check database size:

use <database_name>

Check MongoDB database Size in GB :

db.stats(1024*1024*1024)

Output :

You will get some output like below :

Image 24

Check MongoDB database Size in bytes:

db.stats()

Summarize Collection size :

db.getCollectionNames().forEach(function(collection) {
var stats = db[collection].stats(1024*1024*1024);
print(collection + " - Size: " + stats.size + " GB, Storage: " + stats.storageSize + " GB, Index: " + stats.totalIndexSize + " GB");
});

Hope this helps!! Also, you can get further information from the below official document as well.

Storage Engines for Self-Managed Deployments

Other MongoDB-related Articles:



Leave a Comment

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

Scroll to Top