Opend
← All company guides

Free interview prep

Get ready for
MongoDB.

Indexes · replication · data modelling

MongoDB · Opend practice case · Updated

Which index gets the newest 20 orders onto the screen?

A merchant dashboard reads one tenant’s open orders, sorted by creation time descending, with a page size of 20. The collection has millions of documents. A second dashboard adds a minimum order total. Do these screens need the same index?

Short answerUse the exact query shape to propose a compound index. Compare keys and documents examined, sort work and write cost on production-shaped data before deciding.

Read one tenant’s newest open orders
  • Seek the prefix

    tenantId = T9, status = open. These equality fields identify one contiguous index interval.

  • Read in order

    createdAt descending gives the requested order within that interval.

  • Stop after 20

    Fetch the matching documents for display. Add a stable tie-breaker if the result is paginated.

Translate the query into an access path

For the first screen, try { tenantId: 1, status: 1, createdAt: -1 }. A single-field time index could also return recent orders in order, but it may walk past many other merchants’ records. With a tenant-and-status prefix, the scan starts inside the relevant interval. If two orders can share a timestamp, include a unique tie-breaker in both the sort and the index when implementing a cursor.

Use a second workload to challenge the first design

Now require total above a high threshold. Putting the range field after the time field retains the requested order, but the engine might scan many entries to find 20 large orders. Putting a highly selective range before the sort can reduce the candidate set enough to make a small in-memory sort worthwhile. MongoDB’s equality, sort and range guidance describes both choices.

MongoDB compound index ordering ↗

Explain what the measurements can prove

The sample runs below return the same 20 full documents. The compound index examines one key per result in this simplified case. That ratio says more about avoidable work than a single warm-cache timing. Inspect the winning plan for a blocking sort, then repeat with a large tenant and a sparse tenant. Finally measure representative writes and index size. Keeping a second index is a workload decision with an ongoing write cost.

MongoDB execution statistics ↗
Illustrative execution stats for the first dashboard
PlanKeys / docs examinedReturned
Time index only820 / 82020
Tenant, status, time20 / 2020
Collection scan and sort0 / 40,00020
Try the follow-upA colleague sees zero keys examined and declares the collection scan fastest. How do you respond?

Read totalDocsExamined and the plan stages with the key count. The collection scan visited 40,000 documents. Zero index keys simply identifies the access path. To choose a plan, compare result correctness, resource use and repeated timings under representative traffic.

Interview rounds & focus areas

MongoDB's engineering careers page describes an initial technical interview within its recruiting process. Confirm the rest of your loop with the recruiter; the topics below are Opend's practice recommendations.

  1. PREP FOCUS 01

    Coding & problem solving

    Practice a small, testable solution. Explain data structures, complexity and edge cases aloud.

  2. PREP FOCUS 02

    LLD / HLD

    Reason about index choices, read/write tradeoffs, consistency and failure recovery using explicit workloads.

  3. PREP FOCUS 03

    Practical systems & work discussion

    Walk through one project you shipped: the constraint, your decision, a failure, and the result you can substantiate.

More practice questions

Try each Opend practice question before opening its hints.

How would you choose an index for a slow query?Databases / practical systems · Open solution hints
  1. Start with query predicates, sorting, selectivity and the execution plan.
  2. Compare examined documents to returned documents, then test a compound index against real workloads.
  3. Account for write amplification and storage cost before adding more indexes.
What changes when a replicated database loses its primary?Distributed systems · Open solution hints
  1. State the consistency and durability requirements before discussing elections.
  2. Distinguish acknowledged writes from replicated writes and explain possible retry ambiguity.
  3. Test partitions, delayed replicas and client retry behavior; avoid promising exactly-once delivery.
When would you embed data instead of referencing it?Data modelling / LLD · Open solution hints
  1. Start from access patterns, update frequency and bounded document size.
  2. Compare atomic updates and read locality against duplication and unbounded growth.
  3. Show how your choice changes when the workload or cardinality changes.

Live open roles at MongoDB

Employer sources checked within seven days. This catalogue covers India and worldwide remote engineering openings; confirm location and availability on the employer’s site.

View live roles & check your fit →

Get a free personal fit check →