'mongodb compass not using my index for querying
Hi i am creating index using
db.commerceProduct.createIndex({description : "text"}, {"language_override" : "none", "name" : "test"})
Dataset has about 100K records.
I have two questions:
the description field is not null and neither an empty string. It gives me the following error on using following line in code:
db.commerceProduct.createIndex({description : "text"})
Error : :: caused by :: found language override field in document with non-string type.
I am not able to get why is it so.
Secondly when I make the following query in mongodb compass explain section: It does not uses the index that i created using the first command, to find it.
Query :
{"description" : { $regex: 'Cleanser', $options: 'i' }}
I am not able to understand why it does not uses the created index, Is there any way I can force it ?
Lastly I am trying to optimise the regex query for about 5 fields. I would be thankful if someone can guide me how to do so.
In short it takes about 700ms to do so, which i need to get below 500ms. I am thinking about compound indexing for now to do so. Any other methods are welcomed.
Thank you, have a good day.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
