How to use indexes properly in MongoDB

Boost your MongoDB queries by indexes

Lynn G. Kwong
7 min readMar 14, 2022

--

An issue we often ignore in MongoDB is the indexes. We may take for granted that MongoDB works like Elasticsearch and all fields are indexed by default. Actually, this is not true! In MongoDB, only the _id field is automatically indexed and we need to build indexes for the fields that are queried frequently to support the queries efficiently. Otherwise, the queries can be very inefficient and will degrade the performance of the MongoDB server.

--

--

Lynn G. Kwong

I’m a Software Developer (https://medium.com/@lynn-kwong) keen on sharing thoughts, tutorials, and solutions for the best practice of software development.