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?

Paul White
95.4k30 gold badges440 silver badges689 bronze badges
asked Mar 7, 2018 at 8:39
1
  • 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). Commented Mar 8, 2018 at 3:15

1 Answer 1

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.

answered Mar 7, 2018 at 8:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.