I have a little bit confusion how the json data internally organized (physical storage structure for dynamic schema objects)


let us assuming if we created the indexes on 'x' and 'q', then how the json data internally organized/stored.

Looking for vital suggestions

  • 1
    There is a typo in your second insert statement. It should be "db.some_collection.insert({p:1,q:5,z:"nothing"})" in case someone tries to execute them to follow along with your question.
    – SDillon
    Nov 5 '15 at 13:09
  • If you are trying to understand how Mongo handles BTree indexes, the following video circa 2012 from one of their kernel developers is a good place to start. Start around the 23:30 minute mark of the video. [link]mongodb.com/presentations/storage-engine-internals
    – SDillon
    Nov 5 '15 at 13:24

Your question is very broad as there are multiple storage engines in MongoDB 3.0+ (and a storage engine API). Physical layout for data and indexes will depend on the storage engine implementation, but it sounds like your general question is how documents with varying schemas are stored and indexed.

Conceptually each document is stored in a contiguous binary record allocation which may include padding depending on the storage engine. The server-side document representation is in BSON (http://bsonspec.org) which is a binary JSON-like format with a richer type system than JSON. BSON records can vary in size; indexes (typically B-tree) point to the current location of an indexed record.

MongoDB (as at 3.2) does not maintain any schema information outside of the actual BSON data. Each BSON document includes all of the field names as well as the values. This dynamic schema (or "schema on read") approach allows documents to be interpreted as they are read from storage without consulting or updating a central schema catalog.

For more information, see:

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.