'collection.find({matchQuery}) in MongoDb is taking too long

I am trying to read some limited records after performing a match query on find() collection in mongoDb.

The query takes forever to process. In the next line, I try to read elements of the returned collection and that also takes a lot of time to complete.

Please help where I am making a mistake or scope of improvement.

robot_data = collection.find({"robot_uid": {"$eq":"12345"}},{"_id":0}).sort("_id",1).limit(500) 

 
for a in robot_data :
                print(f"print elements : {a}")    

Regards, Aarushi



Solution 1:[1]

The answer that worked out for me with everyone's help here was to make the search field robot_uid into an index.

The search is extremely fast now.

Thank you! Aarushi

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aarushi Mittal