Add collation to Realm collection

Hi!

We wish to add case insensititvity to some of our collections, which we distribute through Mongo Realm’s GraphQL integration. Hence we have been looking on collations. From what we can understand, you can add collations to existing, populated collections, but then you’ll have to specify the collation in each query you perform (https://docs.mongodb.com/manual/core/index-case-insensitive/#create-a-case-insensitive-index).

On the other hand, you are able to setup a collation which will be inherited in all documents, when you set up your new collection (https://docs.mongodb.com/manual/core/index-case-insensitive/#case-insensitive-indexes-on-collections-with-a-default-collation).

Is there any way for us to specify a collation for a collection in our Realm rules for the given collection? If not, is it possible to somehow add some sort of collation rule that is inherited by all existing documents in the collection, so we don’t have to specify the collation in each database query?

Thanks in advance!

Hey @petas,

There is no way to automatically apply collation through rules or avoid adding the collation for every query unless you’re using a new collection.

If you’re using a default collation that you know you won’t be changing, I suggest creating a new collection and exporting your collection data to the new one.

Another option is to use a custom resolver that adds the collation to every query from the client.

1 Like

Alright, thanks a lot for the quick answer Sumedha!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.