Meteor transform and sorting

Hello !

I have a little problem to transform a collection and sorting the data from.

I have a basic test Collection

/server and client side/
var test = new Mongo.Collection(“test”);

/server side/
return test.find({},{sort:{name:1});

/client side/

I sort in asc order ‘a,c,b’ so the result is -> ‘a,b,c’

Ok for this.
But if i want to transform the collection doc like this ->
test = new Mongo.Collection(“test”, {
transform: function (doc) {
if ( == “b”) { = “z”;
return doc;

The result is -> 'a,z,c’
In fact, the doc ‘b’ has well been replace by ‘z’, but the sort option is not updated so…

I want to transform field name ‘b’ by ‘z’ to have this sort result : ‘a,c,z’

Than’s a lot for your help.


Ok i have found solution ->

Meteor.publish(‘test’, function () {
var self = this;
var result = test.find({}, {
sort: {
name: -1

    added: function (doc) {
        return doc;
return result;