My scenario: I want to display whether a user is currently online to other users. So I am storing the last “ping” time on the user object. For data privacy reasons, I do not want to disclose this information directly to other users.
So I set up a collection transformation function and bound it to the find() method in a publish() method. This transformation compares the ping date with the current date, removes the ping field from the user document and adds an “online” field instead.
This works if I use the find() on server side only. But if I am using the find() in the publish() method, the transformation is not called. I found out that transformation actually happens if fetch() is called, which is understandable. But in my case it means that it is not working. A client-side transform is not an option, as this would require the ping information to be passed to the client.
Is there any other way to hook into the fetch() mechanism on server side, so the transformation can be done when the client actually retrieves the data using fetch()?