File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes MongoDB and the fly likes Why have collections? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » MongoDB
Bookmark "Why have collections?" Watch "Why have collections?" New topic

Why have collections?

Benjamin Weaver
Ranch Hand

Joined: Apr 08, 2003
Posts: 161
I am a MongoDB newbie trying to understand this database.

If collections are not schema-fixed, that is, if documents can vary with regard to number and kind of field, why would one ever have more than 1 collection per database? What is the advantage of having multiple collections in one database?

Any perspectives are greatly appreciated!
chris webster

Joined: Mar 01, 2009
Posts: 2288

Collections are analogous to tables in a relational DB. So you would store similar/related data structures in a collection, perhaps with nested documents to replace relational joins and foreign keys. You can store documents with different attributes in the same collection, but you would still be wanting to have some logical consistency across your collection e.g all Customer details in one collection.

But putting all your data in one collection would be like putting it all in one table. You need the extra layer of abstraction to organise your data sensibly, index things correctly, and so on. Also, a single document (analogous to a record in an RDBMS) cannot be more than 16MB in Mongo, which is fine for many purposes but probably not if you're trying to squeeze your whole database into one collection. When you are querying data, you try to ensure that the data (or at least the indexes) for your working set will fit into RAM to minimise disk I/O, which will be hard to achieve if every query has to trawl through your entire database in a single collection.

If you want to find out more about MongoDB, I can highly recommend the free online courses from 10Gen. Check them out at

PS: I'm really psyched up about MongoDB cos I just attended the great MongoDB Days 2013 conference today in London. :-)

No more Blub for me, thank you, Vicar.
I agree. Here's the link:
subject: Why have collections?
jQuery in Action, 3rd edition