插入后使用流星收集钩子

时间:2016-04-23 18:21:01

标签: meteor

我想在插入后写入另一个集合,对于那个任务,我正在使用meteor collection hooks package https://github.com/matb33/meteor-collection-hooks

我想知道如何在插入后触发回调。我正在使用此代码插入

 'schoolNew': function(post){

      Schools.insert({
          schoolname: post.input_sn,
          schooldescription: post.input_sd,
          schoollocation: post.input_sl,
          schoollogo: post.input_ls
      });
},

正如文档所说https://github.com/matb33/meteor-collection-hooks#afterinsertuserid-doc

  

插入文档后被解雇。

我究竟如何使用回调?。

2 个答案:

答案 0 :(得分:2)

您只需定义集合挂钩,例如:

Schools

并且每次(!!!)插入{{1}}集合后都会自动调用它。

答案 1 :(得分:0)

我添加了这样的钩子

  'schoolNew': function(post){

      Schools.insert({
          schoolname: post.input_sn,
          schooldescription: post.input_sd,
          schoollocation: post.input_sl,
          schoollogo: post.input_ls
      });
      Schools.after.insert(function (userId, doc) {
      var newid = this._id;
      console.log(newid);
     });
},

我确实遇到过问题,但此评论会对您有所帮助https://github.com/vsivsi/meteor-job-collection/issues/58#issuecomment-72272402