3

It looks like mongodb already supports collation: https://docs.mongodb.com/manual/reference/collation/, and by using that on collection level, we can perform case insensitive queries.

Is there a way to use this collation feature in Doctrine ODM? I want to perform some case insensitive searches.

Using regex is not a solution since collection is huge. I'm also aware of the solutions like converting value to lowercase before hand, or also keeping lowercased version with the original value.

Example from https://jira.mongodb.org/browse/SERVER-90

> db.myCollection.createIndex({city: 1}, {collation: {locale: "en", strength: 2}});

> db.myCollection.insert({_id: 1, city: "New York"});

> db.myCollection.insert({_id: 2, city: "new york"});

> db.myCollection.find({city: "new york"}).collation({locale: "en", strength: 2});

{ "_id" : 1, "city" : "New York" }

{ "_id" : 2, "city" : "new york" }
EastSw
  • 927
  • 1
  • 9
  • 28
  • @NeilLunn according to https://jira.mongodb.org/browse/SERVER-90 it should be possible in 3.4. Am I wrong? – EastSw Jul 04 '17 at 21:43
  • Sorry different issue. The main problem as I see it is applying the modifiers for collation. Index creation is not an issue, but you would need to issue "raw" queries directly off the driver methods in order to use the cursor modifiers. Also keep in mind that for a `$regex` you still need to specify the "case insenstive" flag, even though an index can possibly be used, if anchored: `db.myCollection.find({city: /^new/i }).collation({locale: "en", strength: 2}).explain()` – Neil Lunn Jul 04 '17 at 22:07

0 Answers0