meteor-publish-composite
meteor-publish-composite copied to clipboard
Is transform working in publishComposite expected behaviour?
Describe the bug
The Meteor docs say that transform
is not applied to Cursors returned from publications. So, if one wanted to not publish individual elements in an array field, they can't do this:
// Publication that wants to omit individual elements from an array field
Meteor.publish('myPub', function () {
return MyCollection.find({}, {
transform: (obj) => {
// This function never gets called, so this won't work
obj.someArrayField = obj.someArrayField.filter(element => element !== 'someValue');
return obj;
},
});
});
However, this does work:
// Publication that wants to omit individual elements from an array field
Meteor.publishComposite('myCompositePub', function () {
return {
find() {
return MyCollection.find({}, {
transform: (obj) => {
// This function does get called and modifies the published object
obj.someArrayField = obj.someArrayField.filter(element => element !== 'someValue');
return obj;
},
});
},
};
});
Expected behavior
I would've expected the transform
to not work for publishComposite
too. Is this intended behaviour or an accidental feature?
Tested on v1.8.6