Abhinav Batta
Abhinav Batta

Reputation: 46

mongodb compass is not using "text" index for searching a regex expression

I want to search in mongodb a regex expression using text index (I believe for regex search this one is most beneficial).

There is only one field on which to carry out the query. I have created the index like

{ "final : "text"}

using mongodb compass.

and then when i use this command in integrated mongosh terminal,

 db.hello1.find({"final" : { $regex: 'Cleanser', $options: 'i' }}).hint({final : "text"}).explain()

It gives me the following error:

planner returned error :: caused by :: hint provided does not correspond to an existing index

While clearly the compound index exits, of type text _fts(text) _ftsx.

Can someone guide me around this ?

Upvotes: 0

Views: 1147

Answers (1)

Gibbs
Gibbs

Reputation: 22964

It is not designed that way

Case insensitive regular expression queries generally cannot use indexes effectively. The $regex implementation is not collation-aware and is unable to utilize case-insensitive indexes.

Reference

Upvotes: 1

Related Questions