How to use MongoDB
5th Oct 2016


MongoDB (from humongous) is a cross-platform document-oriented database. Classified as a NoSQL database, MongoDB eschews the traditional table-based relational database structure in favour of JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster. Released under a combination of the GNU Affero General Public License and the Apache License, MongoDB is free and open-source software. https://en.wikipedia.org/wiki/MongoDBWhen you look at the blue trend line above it certainly seems that MongoDB is rapidly becoming popular as a Database system. However, looks can deceive sometimes (and it also shows how easy it is to skew data). Check out the search volume of MongoDB (blue) against MySQL (red) in the graph below.[caption id="attachment_3463" align="alignnone" width="299"]




Foursquare is using MongoDB. Harry Heymann says in the comments on Jul 8, 2010: "Foursquare currently has 6 MongoDB instances in production (3 masters, and 3 slaves). We expect this to increase significantly over time. I can say however that we're very pleased with MongoDB thusfar." According to their presentation from MongoSF [9], Bit.ly are using MongoDB to store and serve user history. Bit.ly currently see "~1.25B shortens per month ( 1K/sec peak )", which are logged in MongoDB. SourceForge.net is using MongoDB to store all of their data [10], and it has allowed them to "serve all of the project pages on SourceForge.net without any page level caching."And I really like Steve's answer to the question "What are the main benefits of MongoDB for WebApplications" --> after all Mongo DB is a tool, like there are many more. Understand what the tool can do and choose wisely.
That said, there's things about Mongo that are nice, but have more to do with the contrast between relational databases and document stores than with Mongo itself:* Document modeling fits certain use-cases really well. I'm still exploring particular ones, but having embedded comments on some sort of domain model is one that's been spectacular for me.* Document modeling can drastically reduce your queries per page. I have an app that only needs two queries on most pages, because of the 'denormalization'.* Due to the schema-less nature of document stores, it's much faster to get up and running, and to change the way you store your data.There are also some drawbacks:* Don't even bother using 32 bit. You have a 2G database size limit there.* It's fast because by default it only pages stuff out to disk once per second, so you could theoretically lose data.* It's also fast because with certain settings it actually returns before it knows if the write fails or not, this may or may not be what you want.Bottom line: Know your tools. use the best one.
Tomorrow we'll look at reasons why you shouldn't use MongoDB as your Database solution....