简体   繁体   中英

On Create collection in Meteor

In Meteor there is the Accounts.onCreateUser function that calls when a user is created. Is is possible to do this on collections other than the User collection?

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.

I think the behavior from this method its special to the Meteor.users collection.

Option

if you want to have the same behavior from Accounts.onCreateUser i recommend you to look at the meteor-collections-hooks package.

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
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM