Paginated $lookup on a memory-constrained cluster

Run the three strategies yourself. Same data, same result set, same page — only the query shape differs.

loading…

1 · The listing endpoint

Set a page and run all three. Then try page 500 and watch which ones survive.

A · Current implementation

$lookup → $unwind → $match → $sort → $skip
not run yet

B · Reverse the join

customers first → $in → $skip
not run yet

C · Denormalised + ESR + keyset

one compound index, range cursor
not run yet

2 · The search box

An unanchored /term/ cannot use an index. Search for something rare — the scan must read every document before it can say "no results".

Unanchored /term/

COLLSCAN — every document read
not run yet

Anchored /^term/ + index

IXSCAN — b-tree range seek
not run yet
examined per returned is the number that matters: documents the server read for every document you received. When it runs to thousands, cache thrashes, CPU spikes, and a stalled primary is what triggers a replica-set election. Fixing that is cheaper than a tier upgrade.