What is a document in MongoDB?
A document in MongoDB is the basic unit of data storage, analogous to a row in SQL, but as a BSON object resembling JSON.
Key characteristics
- A "key-value" structure A document is a set of fields:
json
{ "name": "Alex", "age": 25, "skills": ["JS", "MongoDB"] }- Flexibility Different documents in the same collection can have different sets of fields. They don't have to share the same "schema".
- Nesting Documents can hold nested objects and arrays, letting you store complex structures right inside a single record.
- A unique
_idEvery document has an_idfield used as its primary key (created automatically if not set).
The essence of it: a document is a self-contained data record, stored in BSON format, supporting nesting and a flexible structure.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.