Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does MongoDB have collections

Tags:

mongodb

MongoDB being document-oriented, the structure of collections seems to be a special case of documents. By that I mean one can define a document to contain other documents. So a collection is just a document containing other documents.

So why do we need collections after all?

like image 896
Randomblue Avatar asked Nov 30 '11 17:11

Randomblue


2 Answers

Logically yes, you could design a database system like that, but practically speaking no.

  • A collection has indexes on the documents in it.
  • A collection requires the documents in it to have unique ids.
  • A document is limited in size.
like image 60
Ian Mercer Avatar answered Sep 24 '22 10:09

Ian Mercer


  • Object ids (_id top-level document attribute) must be unique within a collection. Multiple collections may have the same _id, just like in RDBMs where the key constraint is per-table, yet multiple tables may contain the same value for a key.
like image 31
Tomasz Nurkiewicz Avatar answered Sep 25 '22 10:09

Tomasz Nurkiewicz