Is there a way to use mongodb 3.4 collation?



I am just wondering if there is a way to use the collation support for server side mongodb queries. This is the nodejs syntax:

db.myCollection.createIndex({city: 1}, {collation: {locale: "en", strength: 2}});
// may work as MyCollection._ensureIndex({city:1},{collation: {locale: "en",strength:2}});

db.myCollection.find({city: "new york"}).collation({locale: "en", strength: 2});
//?? any way to do this?


The current MongoDB driver used in Meteor is 2.2.16, so the collation method is available on Meteor’s rawCollection cursors.


could example to run mongodb queres on Meteor?
example I would like to run



createView is not currently supported in the MongoDB driver.


If you use rawCollection, do you lose the benefit of live updates being published whenever changes are written to the database?


No - oplog tailing continues to work as you’d expect :slight_smile:


It is good, if Meteor support View.
We can use it on Tabular, Report .....


This is not a Meteor issue. This is the official MongoDB Javascript driver package. As soon as that gets support, so will Meteor.


Great! Thank you for the information.


Thanks @robfallows, I don’t know about this.


@robfallows, would you please give an example of how to do this in a publish function? RawCollection I don’t think gives a cursor that is compatible with meteor.

I tried return Meteor.wrapAsync(Items.rawCollection().find(searchCriteria).collation(defaultCollation))(), but it’s not working as I would hope.

I am using the collection hooks package and need that to still work. Unfortunately it doesn’t seem to work with rawCollection. Any ideas on what to do?


I’ve not had a chance to look into this. However, the Meteor Cursor functionality is here:

If I get some time I’ll look into this, but if you get an answer first I’d love to see it :slight_smile:


Thanks for the reply Rob. I looked through what you posted, and it was really helpful. I think I would be able to make some changes to get it to work with find actually, and I don’t think it would be too complicated. However, I just decided to recreate all my collections with a default collation, which is better than having to manually specify a collation every time I do a find operation.


@turbob how did you manage to recreate your collections with a default collation? I’m going through the same process now myself.


This is the most important code. I actually ended up creating a new temp collection, copying all documents there, then recreate old collection with collation and recopy. annoying but it works.

    var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
                    db.createCollection("myCollection", {
                        "collation": {
                            locale: "en",
                            strength: 1


Thanks @turbob, that’s the code I was after. Seems that even if a collection is setup with default collation as above, Meteor only honours the collation if the mongo query is actioned via the server; client queries ignore the collation. I’m assuming this is due to the disparity between the server version of mongodb and the driver version?


No - it’s because you’re limited to minimongo on the client, and there’s currently no support for collations.


Thanks for the clear concise answer @robfallows. As a beginner it was surprisingly hard for me to find this answer anyway else. Makes perfect sense now.