Meteor 插入钩子后,对象没有findOne方法
这很奇怪 我创建了一个钩子,在更新后更新相关集合的一些数据。代码如下所示:Meteor 插入钩子后,对象没有findOne方法,meteor,hook,Meteor,Hook,这很奇怪 我创建了一个钩子,在更新后更新相关集合的一些数据。代码如下所示: @Votes.after.insert (userId, doc) -> person = People.findOne name: doc.candidate person.votes += 1 当我插入一个新的投票时,一切正常:钩子被调用,投票被更新。但是,我在服务器日志中看到了以下内容: Exception while invoking method '/votes/insert' TypeErro
@Votes.after.insert (userId, doc) ->
person = People.findOne name: doc.candidate
person.votes += 1
当我插入一个新的投票时,一切正常:钩子被调用,投票被更新。但是,我在服务器日志中看到了以下内容:
Exception while invoking method '/votes/insert' TypeError: Object [object Object] has no method 'findOne'
在浏览器的控制台上:
errorClass {error: 500, reason: "Internal server error", details: undefined, message: "Internal server error [500]", errorType: "Meteor.Error"}
如果一切正常,我不明白为什么会出现这些错误。是否在某个地方定义了
人员集合?它是在lib
文件夹中定义的,因此它在客户端和服务器上都可用吗?对两者都是。我的模型文件在lib文件夹中,人在People.coffee文件中定义为:@People=new Mongo.Collection(“People”)
,而上面的代码在vote.coffe文件中,在同一文件夹中定义的是人
集合吗?它是在lib
文件夹中定义的,因此它在客户端和服务器上都可用吗?对两者都是。我的模型文件在lib文件夹中,人在People.coffe文件中定义为:@People=new Mongo.Collection(“人”)
,而上面的代码在同一文件夹中的vote.coffe中