javascript – How do document databases (like mongodb) store data behind the scenes?


For a couple of reason which need not be mentioned here, because they are rather complex, I need to program my own NoSQL document database in node.js. However, I am quite confused as to what is the best way to store this data.

I’ve searched around on google, but most information is on how to use a database, not how to program one. The following questions were a blank on google:

  1. To me, the name “document database”, and the fact that the smallest unit of data is a “document”, implies that each one would be stored in an own file. Is this correct?

  2. Also, how are collections grouped together? Is each collection a folder of documents? Or a manifestation file pointing to different documents in a collection?

  3. How should relations between documents be implemented? Is it compliant to the term “NoSQL database” to even have a concept of relations?

  4. Should a NoSQL database contain a way to create schemas for documents, or should NoSQL databases be free-form and schema-less?

I would greatly appreciate it if anyone can answer these questions!👍