MongoDB & Mongoose
Document modeling, aggregation, indexes, and consistency.
What are documents, collections, BSON and ObjectId?
MongoDB stores records as documents, which group related field values in one JSON-like structure. A collection holds documents, and BSON is the binary encoding that supports values such as dates and ObjectIds. An ObjectId is a common identifier format with a timestamp component, but it is not an authorization mechanism or a strict business ordering guarantee.
When should I embed data or reference it?
Embedding stores related data inside one document, while referencing stores a link to data in another document. Embedding makes related reads and single-document atomic updates convenient, but can duplicate data or create oversized documents. Referencing supports independently managed data at the cost of additional reads or joins.
How do I model relationships and schema changes?
Data modeling describes how records relate and how the application retrieves and changes them. Schema evolution is the process of changing that structure while old data and possibly old application versions still exist. MongoDB's flexible document shape makes gradual migration possible, but compatibility still needs planning.
What is denormalization?
Denormalization stores a fact in more than one place to make common reads simpler or faster. It trades extra storage and update work for fewer lookups. Some copies are historical snapshots, while others must track the current source of truth; those are different consistency requirements.
Difficulty is an editorial estimate. Completion means you chose to mark a question as understood.