1

We've currently got a Rails 4 app using MongoDB (v2.4.14) and with Mongoid (5.2.1) as the ODM. I've noticed a problem with our application whereby you search for user say 'Lordon'

User.where(last_name: 'Lordon')

and I expect it to return results containing 'Lordôn' as their last name. I think this behaviour just worked out of the box in MySQL and I've come to expect it.

Is there any configuration to allow for this in either MongoDB or Mongoid without going down the fulltext searching route which is the only solution I've found this morning.

Many thanks.

RobL
  • 37
  • 1
  • 5
  • No sane db should disregard diacritics by default. That behavior is most likely from using a really sloppy encoding and is just bugs waiting to happen. – max Aug 19 '19 at 15:40

1 Answers1

1

Creating a collection with an appropriate default collation should permit searching that collection without specifying collation for each operation: https://docs.mongodb.com/mongoid/master/tutorials/mongoid-persistence/#set-a-default-collation-on-a-collection

If the collection already exists, it would need to be dropped and recreated.

This functionality appears to be supported by Mongoid 5.2 (https://docs.mongodb.com/mongoid/5.2/tutorials/mongoid-persistence/#set-a-default-collation-on-a-collection).

D. SM
  • 13,584
  • 3
  • 12
  • 21
  • Thanks for that. I think we're going to have to wait until we upgrade to MongoDB 3.4 as mentioned here. https://stackoverflow.com/questions/43138189/mongodb-diacriticinsensitive-search-not-showing-all-accented-words-with-diacrit Took my first step into the Mongo console and it just felt so unfamiliar and I couldn't work out how to query the collections current collation, either way I think this is where the solution lies. Thanks. – RobL Aug 23 '19 at 08:24