javascript - 关于在 Meteor 中创建集合

标签 javascript meteor

在 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/

相关文章:

javascript - 谷歌浏览器扩展,一键删除浏览历史

javascript - 误解 `each...in` 用 react 变量渲染

amazon-s3 - 如何使用 meteor 将图像从 FileReader 上传到 Amazon s3

javascript - 如何隐藏div html?

javascript - 使用semantic-ui-react显示svg?

meteor - 所有模板的事件处理程序?

javascript - Meteor.wrapAsync 导致 Meteor 无响应

javascript - Meteor/Cordova 手势与 hammer.js

javascript - 使用 Spring Model 属性设置 js 变量

javascript - Google Maps Geocoding API,其 JS api 中缺少 API 的功能(?)