How to Control Your Expanding MongoDB Database
Join the DZone community and get the full member experience.Join For Free
The key question asked by DJ Walker-Morgan in this recent post from MongoHQ is an important one: do you actually know how big your database is? As Walker-Morgan points out, most people probably have a number they can point to, but the number may not be communicating exactly what they think it is. However, it really should:
If it’s on your own disk drive you may not be bothered about overly large databases, but in the cloud where you are billed on the amount of resources consumed, we’re talking about real money and how to save it.
Walker-Morgan illustrates the problem, then, by creating an example database and running some experiments. One issue Walker-Morgan observes, for example, is a misunderstanding of the sometimes-inconsistency between total data and database size (in MongoDB, at least). This can occur when collections are deleted, because the database hangs on to the space freed up by removing the data, because it assumes it will be filled with new records. It's simple fix, but if you're not aware that the database is doing that, you may be seeing some inflated sizes.
In Walker-Morgan's example database, at least, he manages to reduce the total size from 2.28 GiB to 112 MiB - that's a pretty serious reduction!
In the full post, Walker-Morgan also looks at a few other ways to control an ever-expanding database and keep things from getting out of hand, as well as some quick tips on the various methods that can help. Do what you can to optimize performance as well, and you'll be doing well with MongoDB.
Opinions expressed by DZone contributors are their own.