0

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?

  • It sounds like the original developers were just after a key/value data store. Serialised blobs miss out on most of the features of MongoDB like secondary indexes and rich query syntax, but replication or sharding may still be applicable for data distribution. As you've noted, this pushes all the work of parsing and manipulating JSON into your application code. This pattern would only fit certain niche use cases (for example, treating MongoDB as a cache for API results that need to be returned in JSON). – Stennie Mar 8 '18 at 3:15
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.