Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why have collections?

 
Benjamin Weaver
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2407
32
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 http://education.10gen.com.

PS: I'm really psyched up about MongoDB cos I just attended the great MongoDB Days 2013 conference today in London. :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic