Upon learning that 3.3.11 supports case insensitive case insensitive (using sorting) I rebuilt my database of 40 million entries to play with this. An alternative was to add, for example, string fields specific to case-insensitive searches and index them.
I asked MongoDB to support the sorting of my collection during creation as a quality here . Therefore, I did this to enable case insensitivity for the entire collection:
db.createCollection("users", {collation:{locale:"en",strength:1}})
After loading the collection, I tried direct queries, for example:
db.users.find({full_name:"john doe"})
... and they return in ~ 10 ms with 50 results. It is case insensitive - so everything is fine. But then I will try something like:
db.users.find({full_name:/^john/})
... or...
db.users.find({full_name:/^john/i})
... and it takes more than 5 minutes. I was so disappointed. After executing explain() it turns out that the index was apparently used, but the query still takes too much time to complete. Could this be due to a bug or incomplete release of the development, or am I doing something fundamentally wrong?
As I do the search “begins with” the regular expression, the query should be lightning fast. Any ideas?
source share