[英]On Create collection in Meteor
In Meteor there is the Accounts.onCreateUser
function that calls when a user is created. 在Meteor中,有一个
Accounts.onCreateUser
函数在创建用户时调用。 Is is possible to do this on collections other than the User collection? 是否可以在User集合以外的其他集合上执行此操作?
I think not, since that method expect to returns a user object. 我认为不是,因为该方法希望返回一个用户对象。
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集合中。
I think the behavior from this method its special to the Meteor.users collection. 我认为此方法的行为对于Meteor.users集合而言是特殊的。
Option 选项
if you want to have the same behavior from Accounts.onCreateUser
i recommend you to look at the meteor-collections-hooks package. 如果您希望
Accounts.onCreateUser
具有相同的行为,建议您查看meteor-collections-hooks包。
So you can do the following. 因此,您可以执行以下操作。
collection.after.insert(function(userId,doc){
//do stuff here similar to Accounts.onCreateUser
doc.subbmitedBy = userId; //for example
doc.createdAt = Date.now(); //from docs
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.