Thursday, 27 April 2017

Mongodb Array Query with case insensitive text

I have a record that looks similar to this...

{
  ...
  data: "Email@test.com",
  ...
}

I am trying to query it with db.collection.find({data: $in {['email@test.com']})

I am querying a collection, and most of the time I will have more than one email to query for. Instead of querying as multiple times for every email I need to check, I would like to just pass in an array of emails to query. The issue here being, that the email is not in the same case so I'm unable to match the emails together. I know that Mongo 3.4 handles case insensitivity better, especially with indices, however I am running mongo 3.2.

I have also tried regex

Any ideas on how to execute this while hitting an index? Or how to set this query up better?



via Patrick Zawadzki

No comments:

Post a Comment