A document is a record—a BSON object with field names and typed values. Field order is preserved; duplicate keys are invalid on insert.
Sample document
db.users.insertOne({
email: 'ada@example.com',
profile: { displayName: 'Ada', locale: 'en-US' },
roles: ['reader', 'editor'],
createdAt: new Date()
})Practice: Run in mongosh on your practice database.
Nested and arrays
Dot notation addresses nested fields: profile.displayName. Arrays support positional and filtered updates later.
Document size limit
Maximum document size is 16 MB—if a blob grows larger, use GridFS or external object storage.
Important interview questions and answers
- Q: Can documents differ in one collection?
A: Yes—schema flexibility allows different fields per document. - Q: 16 MB limit applies to?
A: A single document—not the whole collection.
Self-check
- What notation reads nested field displayName?
- Why store dates as Date type not strings?
Tip: Use Date type for timestamps, not locale-dependent strings.
Interview prep
- Document size cap?
- 16 MB per document maximum.
- Nested fields?
- Dot notation in queries: profile.displayName.