Optimizing Slow MongoDB Queries with Indexes and ExplainOptimizing Slow MongoDB Queries with Indexes and Explain
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
Is your MongoDB query getting slower?
Most developers skip this step. Here's what we do instead. 1) No index on the fields you filter by means MongoDB scans every document in the collection to find a match. 2) Build an index that matches the query; for compound indexes, put equality fields first, then sort fields, then range fields. 3) Run explain with execution stats: you want IXSCAN, not COLLSCAN. Then return only the fields you actually need. Save this for your next slow query.
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started