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

db.some_collection.insert({x:1,y:4,z:34})
db.some_collection.insert({p:1,q:5,z:"nothing"})


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

Looking for vital suggestions
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:


MMAP Storage Engine Internals and Understanding MongoDB Storage (MMAP is the default storage engine through MongoDB 3.0)
A Technical Introduction to WiredTiger (optional storage engine in MongoDB 3.0, default in 3.2)