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?
@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?
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.
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?
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.