javascript - 如何解决 "TypeError: callback.apply is not a function"?

标签 javascript node.js mongodb mongoose

我正在做一个大学项目,我已经阅读了关于我的问题的每一篇文章,但我还没有找到解决方案。也许你可以帮我。

代码如下:

viewerObj.update({_id: currentIDViewerVar} , {minutesWatched: 5},{upsert:true}  , function (err,result) {
                                            
          if (err) throw err;
          console.log("Viewer " + userNameVar + " gespeichert");
          console.log("minsWatched" +minsWatched);
});

我收到以下错误。我看不出我做错了什么。

events.js:160
      throw er; // Unhandled 'error' event
      ^

TypeError: callback.apply is not a function
    at C:\Users\picco\Desktop\TwitchWatcher_v19\TwitchWatcher\node_modules\mongoose\lib\model.js:3388:16
    at Query.callback (C:\Users\picco\Desktop\TwitchWatcher_v19\TwitchWatcher\node_modules\mongoose\lib\query.js:2185:9)
    at C:\Users\picco\Desktop\TwitchWatcher_v19\TwitchWatcher\node_modules\mongoose\node_modules\kareem\index.js:259:21
    at C:\Users\picco\Desktop\TwitchWatcher_v19\TwitchWatcher\node_modules\mongoose\node_modules\kareem\index.js:127:16
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Process finished with exit code 1

提前谢谢您!

最佳答案

您使用了太多参数。

更改此:

viewerObj.update({_id: currentIDViewerVar} , {minutesWatched: 5},{upsert:true}  , function (err,result) {

      if (err) throw err;
      console.log("Viewer " + userNameVar + " gespeichert");
      console.log("minsWatched" +minsWatched);
});

对此:

viewerObj.update({_id: currentIDViewerVar, minutesWatched: 5}, {upsert:true}, function (err,result) {

      if (err) throw err;
      console.log("Viewer " + userNameVar + " gespeichert");
      console.log("minsWatched" +minsWatched);
});

查看文档:

关于javascript - 如何解决 "TypeError: callback.apply is not a function"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42933777/

相关文章:

javascript - 将 JSON 转换为 HTML : Uncaught TypeError: json. forEach 不是函数

javascript - Jasmine对象 “has no method '并返回'”

javascript - 自定义复选框在 ie7 和 ie8 中重复

单击时停止的 Javascript 发光/脉动效果

javascript - Javascript 中的查找/替换任务

spring - MongoDB 的 Morphia、Mongo4j 和 Spring 数据如何比较?

node.js - 在单个 console.log 中输出字符串和对象

node.js - Socket.io 如何在 socket.io 中使用 ssl 证书

node.js - OpenShift 上出现 Mongoose 验证错误,但本地版本没有出现此错误

javascript - 在嵌套 Mongoose 函数完成之前完成循环