MongoDB CPU usage spiked to over 100%


This is a really beginner question. During peak usage of around 1k users, our mongodb server CPU jumped to somewhere around 80% - 180%.
We’re running on a 6-core CPU and 8 GB of RAM.

I checked the mongodb.log and it’s filled with this log:

Could this be the cause of the high CPU usage? If not how do I about finding the cause of this?

Thank you very much.

Welcome to the MongoDB Community @Thearith_Sa!

This query in your log example is performing a collection scan of 535,658 docs in order to do an in-memory sort by createdDate and return 10 documents. The in-memory sort is a likely cause for CPU load if there are many of these queries running concurrently.

This is definitely a case where you want to Use Indexes to Sort Query Results and Explain Results to understand query execution.

This may not be the sole cause of your CPU load, but once you’ve addressed common underperforming queries you’ll have a better view of what slow operations remain.