在我的 libs 文件夹中,我使用 SimpleSchema 创建集合。我想通过 autoValue 将 Meteor.userId 添加到某些字段,如下所示:
Collection = new Meteor.Collection('collection');
Collection.attachSchema(new SimpleSchema({
createdByUser: {
type: String,
max: 20,
autoValue: function() {
return Meteor.userId();
}
}
});
但是,这样做时,我收到以下错误:
Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.
我也试过这个:
var userIdentification = Meteor.userId();
Collection = new Meteor.Collection('collection');
Collection.attachSchema(new SimpleSchema({
createdByUser: {
type: String,
max: 20,
autoValue: function() {
return userIdentification;
}
}
});
不过,这会使我的应用程序崩溃:
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.
有任何想法吗?