在 Meteor 中,有一个 Accounts.onCreateUser
函数在创建用户时调用。是否可以在用户集合以外的集合上执行此操作?
最佳答案
我认为不是,因为该方法期望返回一个用户对象。
The function should return the user document (either the one passed in or a newly-created object) with whatever modifications are desired. The returned document is inserted directly into the Meteor.users collection.
我认为此方法的行为对于 Meteor.users 集合来说很特殊。
选项
如果您想从 Accounts.onCreateUser
获得相同的行为,我建议您查看 meteor-collections-hooks包。
因此您可以执行以下操作。
collection.after.insert(function(userId,doc){
//do stuff here similar to Accounts.onCreateUser
doc.subbmitedBy = userId; //for example
doc.createdAt = Date.now(); //from docs
});
关于javascript - 关于在 Meteor 中创建集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28359335/