Inside my libs folder I create collections using SimpleSchema. I want to add the Meteor.userId to some fields via autoValue like this:
Collection = new Meteor.Collection('collection');
Collection.attachSchema(new SimpleSchema({
createdByUser: {
type: String,
max: 20,
autoValue: function() {
return Meteor.userId();
}
}
});
When doing this however, I receive the following error:
Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.
I tried this as well:
var userIdentification = Meteor.userId();
Collection = new Meteor.Collection('collection');
Collection.attachSchema(new SimpleSchema({
createdByUser: {
type: String,
max: 20,
autoValue: function() {
return userIdentification;
}
}
});
This will crash my application though:
=> Exited with code: 8
=> Your application is crashing. Waiting for file change.
Any ideas?