What is the difference between MongoDB and a relational database?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex MongoDB topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Key differences between MongoDB and relational databases (MySQL, PostgreSQL): Data model: RDBMS uses tables with fixed schema (rows + columns); MongoDB uses collections of flexible documents (JSON-like). Schema: RDBMS enforces schema at the database level (ALTER TABLE to change); MongoDB is schema-flexible by default (documents can have different fields). Relationships: RDBMS uses JOINs and foreign keys for related data; MongoDB uses embedded documents (embed related data in one document) or references (store the related document's _id — like a foreign key, but no enforced referential integrity). Scaling: RDBMS scales vertically well, horizontal sharding is complex; MongoDB has built-in horizontal sharding. Transactions: RDBMS has mature ACID transactions; MongoDB added multi-document ACID transactions in v4.0. Query language: RDBMS uses SQL (standardized); MongoDB uses its own JSON-based query language. Indexing: both support B-tree indexes; MongoDB adds text, geo, and array indexes. When to choose MongoDB: flexible/evolving schema, document-oriented data (user profiles, product catalogs), rapid development, need to embed related data to avoid joins. When to choose RDBMS: complex relationships, strict ACID requirements, complex ad-hoc queries with JOINs, financial data, well-defined stable schema.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.