使用流星收集钩插入

问题描述:

后,我想插入后写入到另一个集合,并为该任务,我使用流星搜集钩子包装https://github.com/matb33/meteor-collection-hooks使用流星收集钩插入

我想知道我将如何插入火灾后回调。 Currenty我使用这个代码中插入

'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

的文档插入后激发。

我该如何使用回调?

+0

插入返回该ID后,您可以获取与该ID的数据。 –

你刚才定义集合钩,像这样的例子:

Schools.after.insert(function(userId, doc) { 
    console.log(this); 
    console.log(userId, doc); 
}); 

,它会自动每隔后(!)插入到Schools收集调用。

+0

听起来不可思议,但它与我拥有的每一个其他包裹混杂在一起https://github.com/vsivsi/meteor-job-collection/issues/58#issuecomment-72272402 –

+1

我知道这很糟糕!在定义'新的JobCollection'之前试试这个:'Mongo.Collection.prototype.constructor = Mongo.Collection'。 – tomsp

我加入了钩这样

'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

+0

'Schools.after.insert'不会进入'方法'。 – tomsp