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.
Q61 [Scenario]: How do you store and query hierarchical category tree structures (e.g., e-commerce categories) in MongoDB?
Common pattern models:
- Parent References: Each node stores
{ _id, name, parent: ObjectId }(fast updates). - Materialized Paths: Each node stores
{ _id, name, path: ',Electronics,Computers,Laptops,' }(fast sub-tree regex queries matching^,Electronics,Computers,). - Array of Ancestors: Each node stores
{ ancestors: [ObjectId1, ObjectId2] }.
- Materialized Paths enable fast sub-tree searches via regex index prefixing.
- Array of Ancestors facilitates fast breadcrumb rendering.
Which hierarchy modeling pattern stores ancestral paths as string paths for fast sub-tree regex searches?
Q62 [Scenario]: An API requires combining Full-Text search with strict category filtering and sorting. How do you optimize this?
Standard MongoDB $text indexes have limitations when combined with sorting and filtering. Modern best practice uses MongoDB Atlas Search (powered by Apache Lucene). Create a custom Search Index definition combining autocomplete, faceted filters, and compound relevancy scoring.
- Use MongoDB Atlas Search for enterprise-grade text search.
- Combines full-text search, fuzzy matching, and multi-faceted filtering.
What technology powers MongoDB Atlas Search for full-text search capabilities?
Q63 [Scenario]: You are building an IoT platform receiving 50,000 sensor telemetry readings per second. How do you model this in MongoDB?
Use native Time Series Collections (introduced in MongoDB 5.0). Define timeField and metaField. MongoDB automatically compresses time series data into optimized columnar storage formats, drastically reducing disk footprint and accelerating measurement aggregations.
- Use MongoDB native Time Series Collections.
- Automatically stores data in compressed columnar formats.
Which specialized collection type compresses high-frequency metric data automatically into columnar storage?
Q64 [Scenario]: Creating a new index on a 100M document collection causes production write timeouts. How do you create indexes safely?
In modern MongoDB (4.2+), indexes are built using an optimized hybrid build process that allows concurrent reads/writes. However, on massive collections, perform rolling index builds across replica set members: take Secondary nodes offline one by one, create the index locally, bring them back online, and finally step down the Primary node to build the index on it.
- MongoDB 4.2+ uses hybrid index builds concurrently.
- Use rolling index builds across replica sets for critical production databases.
What index creation strategy builds indexes on secondary nodes one by one to protect production workloads?
Q65 [Scenario]: An e-commerce system sells products with vastly different attributes (e.g., Laptops have CPU/RAM, Clothing has Size/Color). How do you model this?
Apply the Polymorphic Pattern alongside the Attribute Pattern. Store common fields (title, price, category) at top level, and store variant attributes inside a key-value array: attributes: [{ k: 'size', v: 'XL' }, { k: 'color', v: 'Red' }]. Index the array with a compound multikey index on { 'attributes.k': 1, 'attributes.v': 1 }.
- The Attribute Pattern organizes varying product properties cleanly.
- Compound multikey index
{ 'attributes.k': 1, 'attributes.v': 1 }targets variable product specs.
Which design pattern organizes diverse product specification fields into key-value array objects for indexability?
Q66 [Scenario]: An Express API endpoint looping through posts to fetch author details executes 101 queries for 100 posts. How do you resolve this?
This is the classic $N+1$ query problem. Resolve it by using Mongoose .populate() or a single native Aggregation $lookup stage. Alternatively, extract all author ObjectIds into an array and execute a single batch query: User.find({ _id: { $in: authorIds } }), mapping results client-side.
- Eliminate query loops inside code.
- Use batch
$inqueries or$lookupaggregation joins.
What issue occurs when executing database query requests inside a forEach loop iterating over 100 documents?
Q67 [Scenario]: Compliance requires encrypting sensitive fields (SSN, Credit Cards) such that even database administrators cannot read plain text. How do you satisfy this?
Implement Client-Side Field Level Encryption (CSFLE) or In-Use Encryption. The driver automatically encrypts sensitive document fields on the application client side before sending binary payloads to MongoDB. The database server stores strictly encrypted cipher-text and never possesses the decryption keys.
- Client-Side Field Level Encryption (CSFLE) encrypts data on client drivers.
- Database servers never see unencrypted plain text for CSFLE fields.
Which encryption mechanism encrypts data on client drivers BEFORE sending payloads to MongoDB?
Q68 [Scenario]: A movie document has 50,000 customer reviews. Loading the movie page fetches all reviews, slowing down page loads. How do you optimize this?
Apply the Subset Pattern. Embed strictly the top 10 most recent reviews inside the main Movie document (recentReviews: [...]) for instant page rendering. Store the full complete list of 50,000 reviews in a separate Reviews collection, paginating them on demand.
- The Subset Pattern embeds a small, frequently accessed subset of data.
- Reduces main document size and speeds up initial page load queries.
Which pattern embeds a small subset of frequently accessed data (e.g. 5 recent reviews) in the main document while storing the full list elsewhere?
Q69 [Scenario]: A sharded cluster reports 'Jumbo Chunk' errors and balancer failures. What causes this and how do you fix it?
A Jumbo Chunk occurs when a data chunk exceeds the maximum chunk size (default 64MB) and cannot be split because all documents share the exact same shard key value (low cardinality / field hotspotting). Resolution: Refine the shard key by adding a secondary suffix field to create a compound shard key with higher cardinality.
- Caused by low cardinality shard keys creating indivisible chunks.
- Refine shard keys by appending additional fields to enable chunk splits.
What causes a 'Jumbo Chunk' that cannot be split or moved by the MongoDB cluster balancer?