Mongo High CPU Usage when query

Dear.

I have some problems with my query, i have a table with index created, this table is to store log of my app, and many logs are stored. when i call a query with limit is 10, the average response time is around 1.6s, but the CPU Usage is very high, i don’t know why.

Pls help me to find out the root cause.

Here is my query:

{"where":{"or":[{"inputMessage.SENDERPHONE":{"contains":"0968xxxxxx8"}},{"inputMessage.RECEIVERPHONE":{"contains":"0968xxxxxx8"}}]}}

Hi @Chuong_LA,

Your query is using a $where clause? Please note that $where or map reduce are known to wrok poorly with indexes.

Moreover, regex type queries with un-anchored searches are known to be poor when utelizing indexes.

Notice that the query is probably running a full index scan as it tries to find first 10 records , index keys examine is 300k.

Are you using atlas? If yes please consider using atlas search as it has support for regex indexing for text which should be far more sufficient.

https://docs.atlas.mongodb.com/atlas-search/

https://docs.atlas.mongodb.com/reference/atlas-search/regex/#regex-ref

Best
Pavel