Member-only story
Improve MongoDB Performance Using Projection
Speed up your Mongo database’s performance
This article documents all my findings and analysis on how much performance was improved using projection in MongoDB. At the end of this article, we will be able to know whether MongoDB query performance will be improved by leveraging projection.
Without further ado, let’s start.
Problem Statement
This article was inspired during my working hour where I used projection when I retrieved the data from MongoDB. Projection is “a document given to a query that specifies which fields MongoDB returns in the result set.” according to MongoDB’s Official Documentation.
It’s like ordering a Big Mac at McDonald’s, and we can choose a la carte instead of a full set that comes with drink and fries.
Thus, I was wondering — how much does the query performance improve if projection was used. Here are the primary objectives that I wanted to achieve in this research:
Primary objectives
- Discover whether performance will be improved if projection was used in MongoDB query.
- Discover the best scenario to use projection in MongoDB query.
Solution Analysis
I always started with finding out what I need in order to continue the research. These items are what I needed:
- A collection with more than 500K documents so that I can find out the difference in query time with and without projection.
- Sub-document schema. This is because I suspect the document with sub-documents will increase a significant amount of query time. Let’s prepare this for the experiment as well.
Refer to the screenshot below for the outcome of data preparation. Check out this article on how I generate millions of dummy data for performance optimization.

From this screenshot, we knew that we have generated 500K documents with the following fields: