HomeBytesheetsRoadmapsUI TemplatesUI ToolsStack Discussion
70 Topics
Chapter•360 Minutes

70 Progressive Questions (Easy to Advanced + Scenarios)

70 comprehensive interview questions spanning database basics, Mongoose ODM abstractions, advanced aggregation pipelines, system architecture, performance tuning, and real-world scenario challenges.

Q1: What is MongoDB and how does it differ from traditional RDBMS?

MongoDB is a source-available, document-oriented NoSQL database that stores data as flexible BSON (Binary JSON) documents. Unlike traditional RDBMS (which uses structured tables, fixed schemas, and SQL joins), MongoDB provides flexible dynamic schemas, high availability via replica sets, and native horizontal scaling through sharding.

Key Takeaways
  • Dynamic dynamic schemas vs. fixed relational tables.
  • Stores data in BSON format with native nested objects and arrays.
Knowledge Check

Which data format does MongoDB use internally to store and query documents?

Q2: What is Mongoose and why use it over the native MongoDB driver?

Mongoose is an Object Data Modeling (ODM) library for Node.js. While the native driver provides direct low-level CRUD access, Mongoose adds structure by providing schema validation, type casting, middleware hooks (pre/post), dynamic virtuals, and populated document references.

Key Takeaways
  • Mongoose provides an ODM layer with schema enforcement.
  • Includes auto-casting, middleware hooks, populate references, and validation.
Knowledge Check

What is the primary role of Mongoose in a Node.js application?

Q3: What is BSON and how does it extend standard JSON?

BSON stands for Binary JSON. It is a binary-encoded serialization format used by MongoDB to store data and execute operations. BSON extends JSON by adding support for extra data types (e.g., ObjectId, Date, BinData, Decimal128, Long) and enables faster traversal and indexing by prefixing fields with byte lengths.

Key Takeaways
  • Extends JSON with native types like Date, ObjectId, and 64-bit Int.
  • Includes length prefixes for fast traversal.
Knowledge Check

Which of the following data types is supported natively in BSON but NOT in standard JSON?

Q4: Explain the structure of a MongoDB ObjectId.

An ObjectId is a 12-byte BSON value designed to guarantee uniqueness across distributed systems without a central authority:

  • 4 bytes: Timestamp value (seconds since epoch).
  • 5 bytes: Random value unique to the machine and process.
  • 3 bytes: Incrementing counter initialized to a random value.
Key Takeaways
  • Total size: 12 bytes.
  • First 4 bytes encode a UTC timestamp, allowing natural sorting by creation time.
Knowledge Check

How many bytes does a standard MongoDB ObjectId consume?

Q5: What is the difference between a Mongoose Schema and a Mongoose Model?

A Schema defines the structure, default values, validators, and middleware hooks for documents within a collection. A Model is a compiled constructor built from a Schema that provides the concrete interface to perform database CRUD operations (User.find(), User.create()).

Schema Definition vs Model Creation
const mongoose = require('mongoose');

// 1. Define Schema (Blueprint)
const userSchema = new mongoose.Schema({
  name: { type: String, required: true },
  email: { type: String, unique: true }
});

// 2. Compile Model (Database Interface)
const User = mongoose.model('User', userSchema);
💡 The Schema defines attributes and rules; the Model compiles the schema into an executable database interface.
Key Takeaways
  • Schema = Blueprint & Rules.
  • Model = Compiled class providing CRUD access methods.
Knowledge Check

Which Mongoose call creates the database query interface from a defined schema?

Q6: When should you embed documents vs reference them in MongoDB?

  • Embed (Denormalization): Use when data has a 1-to-1 or 1-to-Few relationship, is accessed together frequently, and data doesn't grow unbounded (e.g., user address list).
  • Reference (Normalization): Use when data has a 1-to-Many (unbounded) or Many-to-Many relationship, data is updated independently, or document size approaches the 16MB limit.
Key Takeaways
  • Embed for atomic updates and high-speed read joins.
  • Reference for large, unbounded collections or shared entities.
Knowledge Check

Which pattern is recommended for storing a blog post's tags (5 to 10 tags per post)?

Q7: What is the maximum document size limit in MongoDB, and how do you store larger files?

The maximum BSON document size limit is 16 Megabytes. This prevents individual documents from overloading RAM or network bandwidth during retrieval. To store files or documents exceeding 16MB, MongoDB provides GridFS, which splits files into 255KB chunks across two collections (fs.files and fs.chunks).

Key Takeaways
  • 16MB maximum single BSON document limit.
  • Use GridFS to automatically chunk and stream large files.
Knowledge Check

Which built-in MongoDB feature supports storing single files exceeding 16MB?

Q8: What are the basic CRUD operations in Mongoose?

  • Create: Model.create({ name: 'Alice' }) or const doc = new Model(); await doc.save();
  • Read: Model.find({ age: { $gte: 18 } }), Model.findOne(), Model.findById()
  • Update: Model.updateOne({ _id }, { $set: { status: 'active' } }), Model.findByIdAndUpdate()
  • Delete: Model.deleteOne({ _id }), Model.findByIdAndDelete()
Key Takeaways
  • save() triggers validation and pre/post save hooks.
  • updateOne/updateMany bypass document instance hooks unless explicitly configured.
Knowledge Check

Which method instantiates a document and triggers Mongoose pre-save middleware hooks?

Q9: Explain fundamental comparison operators in MongoDB ($eq, $gt, $in, $nin).

Comparison operators match field values against criteria:

  • $gt / $gte: Greater than / Greater than or equal to.
  • $lt / $lte: Less than / Less than or equal to.
  • $in: Matches any value specified in an array status: { $in: ['active', 'pending'] }.
  • $nin: Matches values not present in the specified array.
Key Takeaways
  • $in evaluates array matches in a single query pass.
  • Combine operators for bounded range searches { age: { $gte: 18, $lte: 65 } }.
Knowledge Check

Which operator finds documents where a status field equals EITHER 'active' OR 'verified'?

Q10: How do logical query operators ($and, $or, $nor, $not) work?

Logical operators join multiple clause conditions:

  • $or: Returns documents matching at least one clause: { $or: [{ role: 'admin' }, { points: { $gt: 100 } }] }.
  • $and: Joins conditions implicitly or explicitly when querying the same field multiple times.
  • $nor: Returns documents failing all listed conditions.
Key Takeaways
  • Implicit $and occurs when comma-separating conditions in a query object.
  • Use explicit $and when targeting the same operator key multiple times.
Knowledge Check

When is an explicit $and operator required in a MongoDB query?