How to add a field to a document from a server in a publication without saving it?

I want to add and return the calculated field from the Meteor.publish server, which is not actually saved in MongoDB. Is it possible? Something like where I will format some markdown:

Meteor.publish('recentEdits', function(pageId) { var edits, formattedContent; edits = WikiEdits.find({pageId: pageId}, {sort: {ts: -1}, limit: RECENT_EDIT_LIMIT}); edits.forEach(function(edit) { formattedContent = marked(edit.content); edit.formattedContent = formattedContent; }); return edits; }); 

It should seem to the client that the formattedContent field appeared like any other, but this is not really in MongoDB. Is this possible, and if so, what is the best way? Even if I have to keep formattedContent, I would still like to know how to do this.

I tried using the transform option in Meteor.Collection and only worked on the client, but I want this to happen from the server.

+4
source share
1 answer

you can use transform find option

the only problem is that it also runs on the client. If you can live with it, this is the solution.

Another option would be to add an unmanaged collection on the client and retrieve content from the Meteor method

The local unmanaged collection will not be stored in MongoDB, which you can call Meteor.method from autorun and observe will work in the local collection.

+1
source

Source: https://habr.com/ru/post/1486484/


All Articles