UPDATE: It's possible to do a transform on the server.
You can have a transform on the client like this:
return YourCollection.find({}, {transform: function (doc) {
doc.test = true;
return true;
}});
Meteor ignores transform
on queries that are published (from within Meteor.publish
). The client sees the document as if the transform didn't exist.
If you would like to use transforms on the server you can do this:
YourCollection = new Mongo.Collection("collection_name");
Meteor.publish("yourRecordSet", function() {
//Transform function
var transform = function(doc) {
doc.date = new Date();
return doc;
}
var self = this;
var observer = YourCollection.find().observe({
added: function (document) {
self.added('collection_name', document._id, transform(document));
},
changed: function (newDocument, oldDocument) {
self.changed('collection_name', newDocument._id, transform(newDocument));
},
removed: function (oldDocument) {
self.removed('collection_name', oldDocument._id);
}
});
self.onStop(function () {
observer.stop();
});
self.ready();
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…