{"action":"created","issue":{"url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/28","labels_url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/28/comments","events_url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/28/events","html_url":"https://github.com/englue/meteor-publish-composite/issues/28","id":53987734,"number":28,"title":"Compatibility with added/changed/removed in publish","user":{"login":"steph643","id":7039479,"avatar_url":"https://avatars.githubusercontent.com/u/7039479?v=3","gravatar_id":"","url":"https://api.github.com/users/steph643","html_url":"https://github.com/steph643","followers_url":"https://api.github.com/users/steph643/followers","following_url":"https://api.github.com/users/steph643/following{/other_user}","gists_url":"https://api.github.com/users/steph643/gists{/gist_id}","starred_url":"https://api.github.com/users/steph643/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steph643/subscriptions","organizations_url":"https://api.github.com/users/steph643/orgs","repos_url":"https://api.github.com/users/steph643/repos","events_url":"https://api.github.com/users/steph643/events{/privacy}","received_events_url":"https://api.github.com/users/steph643/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/englue/meteor-publish-composite/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-01-11T10:17:26Z","updated_at":"2015-08-11T18:45:44Z","closed_at":null,"body":"As you know, there are two methods to implement a publish function:\r\n1. By returning a cursor (or an array of cursors)\r\n2. By using `this.added()` / `this.changed()` / `this.removed()`, usually from `cursor.observeChanges()` callbacks\r\n\r\nLet's consider these three use cases for method 2:\r\na. You want to add a field to a document before publication\r\nb. You want to remove a field from a document before publication\r\nc. You want to do both, for example to combine several secret fields into one public field\r\n\r\nDoes *meteor-publish-composite* allow for these three use cases?"},"comment":{"url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/comments/130012786","html_url":"https://github.com/englue/meteor-publish-composite/issues/28#issuecomment-130012786","issue_url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/28","id":130012786,"user":{"login":"reywood","id":1796302,"avatar_url":"https://avatars.githubusercontent.com/u/1796302?v=3","gravatar_id":"","url":"https://api.github.com/users/reywood","html_url":"https://github.com/reywood","followers_url":"https://api.github.com/users/reywood/followers","following_url":"https://api.github.com/users/reywood/following{/other_user}","gists_url":"https://api.github.com/users/reywood/gists{/gist_id}","starred_url":"https://api.github.com/users/reywood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reywood/subscriptions","organizations_url":"https://api.github.com/users/reywood/orgs","repos_url":"https://api.github.com/users/reywood/repos","events_url":"https://api.github.com/users/reywood/events{/privacy}","received_events_url":"https://api.github.com/users/reywood/received_events","type":"User","site_admin":false},"created_at":"2015-08-11T18:45:44Z","updated_at":"2015-08-11T18:45:44Z","body":"This is definitely tricky. `publishComposite` uses both `observe` and `observeChanges`. It uses `observe` because it needs the whole document when updating child publications. The `observe` handler is also used to send \"added\" and \"removed\" updates to the client. It uses `observeChanges` to send changes to the client, because, as mentioned elsewhere, it is more efficient. The upshot is that transforms are applied to documents when they are \"added\". The catch is that transforms are not applied when a document is \"changed\" due to the use of `observeChanges`. If transforms were applied to changes, it's not clear how that would work since you'd only have the changed fields, not the whole document.\r\n\r\nSo, to address @steph643's original questions:\r\na. Yes, you can use the `transform` option of the `Collection.find` method to add fields to a document before publication. However, the transform will not be called if/when the document changes. This means that if a field used in your transform changes, the transformed fields will not be updated.\r\nb. If you want this removed field to still be visible to child publications (which I presume is what you want, otherwise, why bother), then you're currently out of luck.\r\nc. See answers to a and b\r\n\r\nI've considered adding a `transform` option to `publishComposite`, but this would still have the issues described above when a document changes. I'm open to thoughts and ideas."}}