What is a collection in MongoDB?

Why Interviewers Ask This

This is a classic screening question for MongoDB roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

A collection is a group of MongoDB documents, analogous to a table in a relational database. Collections don't enforce a schema by default — documents in the same collection can have different structures (though in practice, they usually store the same type of data). Key points: (1) Collections exist within a database; a MongoDB deployment can have multiple databases, each with multiple collections; (2) Collections are created lazily — when you first insert a document; (3) Capped collections: fixed-size collections that maintain insertion order and automatically overwrite oldest documents when full. Useful for logs, caches; (4) Naming: collection names can contain any UTF-8 characters except null, $, and system prefix; recommended: lowercase, snake_case (e.g., user_profiles); (5) Schema validation: MongoDB supports optional JSON Schema validation rules on collections, enforcing field types and required fields while keeping flexibility. Commands: db.createCollection("orders") (explicit creation); show collections (list all); db.orders.drop() (remove collection + all documents).

Common Mistake

Many candidates answer correctly but can't explain the 'why'. Always be prepared to justify your answer with a concrete example or use case from your MongoDB experience.