Question :
Wondering if I could get some insight on a design I saw recently. A collection can contain a few or tens of thousands of documents.
Each document has the same structure of _id
and JSONValue
. The latter just contains a large string which contains the JSON for that document.
I can’t quite understand why this is useful? You can’t query it easily. It seems to me like MongoDB is just a data store with the application doing all the grunt work.
Am I missing the point? Can you suggest some use cases for this design approach?
Answer :
In MongoDB, documents stored in a collection require a unique _id
field that acts as a primary key. If an _id
does not exist in the document, MongoDB will create an ObjectID
field. Generally, _id
can itself be a complex document, any BSON data type (still, it must be unique). ObjectID
() is described Here.
As MongoDB internally to store documents in BSON format. BSON extends the JSON model to provide additional data types and to be efficient for encoding and decoding within different languages. MongoDB BSON implementation supports embedding objects and arrays within other objects and arrays – MongoDB can even reach inside BSON objects to build indexes and match objects against query expressions on both top-level and nested BSON keys.
As MongoDB documented Here Data in MongoDB has a flexible schema. Collections do not enforce document structure. Decisions that affect how you model data can affect application performance and database capacity.
This document describes a data model that uses embedded documents to describe relationships between connected data.