Mongodb uses 100% CPU usage searching in more than 1M documents

I installed mongodb 4.4.3 on my ubuntu server(4 cores and 8GB of ram SSD)
I have a collection of icons that contains more than 1M documents

On my backend I’m using node js and mongoose
The problem is when I want to search in the icons collection, only one reqest uses 100% CPU, but the weard thing is that mongodb is still using the cpu (100%) about 10 seconds or so after delivering the response, I don’t understant why that

how can I fix that?

here is my code:
const icons = await Icon.find({name: ‘car’}).limit(100).lean();

Hi @Hamza_Mihfad,
Try adding an index on the “name” field of the “icons” collection.
Run this from the mongo shell:

use YourDatabaseName
db.icons.createIndex({name: 1})

Goodluck,
Rafael,

1 Like