After finding out that 3.3.11 supports case insensitive index (using collation) I have rebuilt my database of 40 million records to play with this. Alternative was to add e.g. lowercase fields specific to case insensitive search and index those.
What I did was to ask MongoDB to support collation on my collection at the time of creation as suggested here. So I did this to enable case insensitivity for the entire collection:
db.createCollection("users", {collation:{locale:"en",strength:1}})
After loading the collection I have tried direct queries like:
db.users.find({full_name:"john doe"})
...and those return in ~10ms with 50 results. It's case insensitive - so all is great. But then I try something like:
db.users.find({full_name:/^john/})
...or...
db.users.find({full_name:/^john/i})
...and this takes more than 5 minutes. I was so disappointed. After doing explain()
it turns out that the index was apparently being used but the query still takes way too long to execute. Can this be attributed to buggy or incomplete development release or am I doing something fundamentally wrong?
As I am doing a "starts with" regex search, the query should be lightning fast. Any ideas?