Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 插入钩子后,对象没有findOne方法_Meteor_Hook - Fatal编程技术网

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中