vs MongoDB — SQL Technical Interview Questions & Answers

vs MongoDB

vs MongoDB

  • MySQL: tables, fixed columns, JOINs, SQL, FOREIGN KEYs. MongoDB: collections of JSON-like documents, flexible fields, no JOINs in the SQL sense (you embed or $lookup).
  • Pick MySQL when data is tabular and relationships matter (student–marks–fees). Pick Mongo when documents vary and you load one blob per user. Both can be right. ‘NoSQL is always faster’ is false.
  • Trap: forcing a 6-table JOIN into Mongo, or storing a 20-level JSON in MySQL because ‘JSON column exists’.
  • On the example next to this theory: vs MongoDB: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Technical Interview Tip: Tables+JOIN vs documents. Pick by data shape, not hype.

Code Examples for vs MongoDB

vs MongoDB — sample query

-- vs MongoDB
CREATE TABLE demo (
  id INTEGER PRIMARY KEY,
  label TEXT NOT NULL,
  qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
  (1, 'alpha', 2),
  (2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;

vs MongoDB: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

How to Explain vs MongoDB to an Interviewer

When MySQL over Mongo?

Fixed schema JOINs and FOREIGN KEYs