MongoDB is a client/server document database. A mongod process stores data; clients (mongosh, drivers in Python/Node) send commands over the wire.
Core characteristics
- Document model — nested JSON-like structures map cleanly to app objects
- Flexible schema — documents in one collection can differ (within validator rules)
- Rich queries — operators on fields, arrays, and embedded objects
- Aggregation pipeline — multi-stage analytics without always exporting to SQL
- Horizontal scale — sharding for very large datasets (preview later)
Hierarchy: cluster → database → collection → document
show dbs
use practice
show collections
db.users.findOne()A deployment hosts databases; each database has collections; each document has an _id (often ObjectId).
Practice: Copy queries into mongosh, MongoDB Atlas Data Explorer, or Compass. Use a database named practice you create for learning.
Who uses MongoDB?
Common in content platforms, catalogs, mobile backends, event logs, and polyglot stacks (SQL for ledger, Mongo for product JSON). Pair with Python (PyMongo) and Node.js (Mongoose).
Important interview questions and answers
- Q: BSON vs JSON?
A: BSON is binary JSON with extra types (Date, ObjectId, Decimal128)—what MongoDB stores on disk. - Q: Is MongoDB schemaless?
A: Schema-flexible, not schema-less—you should still design fields, indexes, and validators intentionally.
Self-check
- Name the four levels from deployment down to document.
- What field uniquely identifies a document by default?
Tip: Remember cluster → database → collection → document when reading shell output.
Interview prep
- BSON vs JSON?
- BSON adds types like ObjectId and Date; MongoDB stores BSON on disk.
- Default _id?
- ObjectId generated on insert when omitted.