7

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?

Randomblue
  • 112,777
  • 145
  • 353
  • 547

3 Answers3

8

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.
Ian Mercer
  • 38,490
  • 8
  • 97
  • 133
1
  • 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.
David O.
  • 366
  • 1
  • 7
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
0

collections is a container for documents. so when you say a document that contain other documents that s kinda wrong because, already, a document can have inner documents.

Collection is the unit where you put together the documents. Be aware that due to schema free design, you can put anything in a collection but it s not a good design. so collection is kinda logical container for documents. same as tables in relational world.

DarthVader
  • 52,984
  • 76
  • 209
  • 300