Cpu utilization is more to search 5 million record using regex expression any other optimized way to search

db.student.find($regex:{“spn”})

That query produce a syntax error:

SyntaxError: Unexpected token, expected "," (1:22)

> 1 | db.student.find($regex:{“spn”})
    |                       ^

db.products.find( { name: { $regex: /^ABC/i } } )

Do you have an index on this field?

Are you sure you are using the correct collection? You went from

to

If you do not have an index on the queried field on the appropriate collection, then a collection scan will occur. If you created an index on the student collection and do the find on the products collection, a collection scan will occur. If you created an index on the products collection and do the find on the student collection, a collection scan will occur.

The very first step is to make sure you have an index on the appropriate field name of the appropriate collection name and to perform find on the same appropriate field name of the same appropriate collection name. Any typos or confusion about the field name or collection name will result in a slow collection scan for the find.

Some reading to do about indexes: https://www.mongodb.com/docs/manual/applications/indexes/ , Performance Best Practices: Indexing | MongoDB Blog , https://www.mongodb.com/docs/manual/indexes/ and https://www.mongodb.com/docs/manual/reference/method/cursor.explain/.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.