【发布时间】:2016-01-31 09:00:53
【问题描述】:
使用 dburles:collection-helpers 包,您可以在任何 Mongo.collection 上添加集合助手。但我不能在 FS.Collection 上这样做。我得到 TypeError: Object [object Object] has no method 'helpers'。变换功能也不起作用。
var createUploader = function(fileObj, readStream, writeStream) {
fileObj.uploadedBy = Meteor.users.find({_id: fileObj.uploader});
readStream.pipe(writeStream);
};
Photos = new FS.Collection("photos", {
stores: [
new FS.Store.GridFS("photos", {transformWrite: createUploader})
],
filter: {
allow: {
contentTypes: ['image/*']
}
}
});
不能这样做吗?注意当从客户端插入照片时FS.File 得到userId,因此fileObj.uploadedBy = Meteor.users.find({_id: fileObj.uploader});
【问题讨论】:
-
在 CollectionFS 文档中,说 可通过 myFSCollection.files 获得的基础 Mongo.Collection 实例 错过了该部分。但仍然出现错误:错误:[Can't apply helpers to 'cfs.photos.filerecord' a transform function already exists!]
-
我刚刚发现 atmospherejs.com/maximum/multi-transform 可以帮助您将类似帮助程序的转换应用到您的 collectionfs 实例。
标签: meteor meteor-helper collectionfs