Transform on server

The documentation states that you can specify a transform function on the Mongo.Collection and/or with on a Collection.find()

It does not specify where the transform runs, client or server side.

I have been fiddling with this, thinking I can attach a transform to the Collection.find inside a publish, which does not seem to work.

Can someone confirm how and where exactly a transform can occur, and if I just overlooked something in the docs? I could not find any mention that it would not work inside a publish.

well, I would expect that after transformation it would not be cursor anymore.
So low level publish API ?

And DDP transport only E-JSON data types, so no functions…

From the docs:

… Documents will be passed through this function before being returned from fetch or findOne, and before being passed to callbacks of observe, map, forEach, allow, and deny. Transforms are not applied for the callbacks of observeChanges or to cursors returned from publish functions.

The point being that the cursor returned from a publication will not have the transform applied. Only when a document is fetched (either explicitly with fetch or findOne, or implicitly - as with Blaze), will the transform be executed.

So, it will run on client or server, depending on how you reference the documents in your collection.

3 Likes

@jamgold: Did you find a way to circumvent this? I ran in the very same problem (did not see your post before I posted mine):

Thank you @robfallows , that answered both my questions. I clearly did not catch the last part of the sentence.

1 Like

@waldgeist, I am using the low level added/changed in my publish function.

1 Like

Thanks for your quick reply!

@jamgold I think we’ve discussed this same topic on a somewhat unrelated thread.

FWIW, I’m using reywood:publish-composite and it allows transforms within the publish functions. And they happen to work. There may be perforamance implications though. And then, there’s this comment from the author himself, elaborating on the topic.

I think this thread should be closed, because it was a PEBCAK on my behalf, since I didn’t read the documentation right. And I started the other thread as well … :wink:

Haha :slight_smile: Well, FWIW, I believe the rationale behind the request for a transform within the publish function does have merit.