【问题标题】:Mongoose: "TypeError: "listener" argument must be a function" on connectMongoose:“TypeError:“listener”参数必须是一个函数”连接
【发布时间】:2017-07-30 18:54:40
【问题描述】:

我正在尝试将Mongoose 与 typescript 2.2.1、express 4.15.2 和 node v7.7.2 一起使用,但是当我尝试连接到 mongodb 时,它会引发此错误:

TypeError: "listener" argument must be a function
at Socket.once (events.js:307:11)
at Socket.connect (net.js:943:10)
at Socket.connect (/home/fabian/Projects/Huis-Pils/node_modules/async-listener/index.js:76:27)
at Object.exports.connect.exports.createConnection (net.js:76:35)
at Connection.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb-core/lib/connection/connection.js:399:11)
at Pool.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb-core/lib/connection/pool.js:638:16)
at Server.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb-core/lib/topologies/server.js:384:17)
at Server.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongodb/lib/server.js:361:17)
at open (/home/fabian/Projects/Huis-Pils/node_modules/mongodb/lib/db.js:226:19)
at Db.open (/home/fabian/Projects/Huis-Pils/node_modules/mongodb/lib/db.js:249:44)
at NativeConnection.doOpen (/home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:58:11)
at NativeConnection.Connection._open (/home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:531:15)
at /home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:289:11
at new wrappedPromise (/home/fabian/Projects/Huis-Pils/node_modules/async-listener/index.js:372:16)
at NativeConnection.Connection.open (/home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:288:17)
at Mongoose.connect (/home/fabian/Projects/Huis-Pils/node_modules/mongoose/lib/index.js:242:47)

代码:

 import * as mongoose from "mongoose";
 (<any>mongoose).Promise = global.Promise;
 mongoose.connect('mongodb://localhost/test');

我就是想不通我做错了什么。

【问题讨论】:

    标签: javascript node.js mongodb typescript mongoose


    【解决方案1】:

    我有类似的问题,它可能是 Node 7.7.2 的错误

    如果那样的话,应该由https://github.com/nodejs/node/pull/11762解决

    【讨论】:

    • 是的,我相信是这样,我下载了 node v6.10.0 并且我在那里没有任何问题。很好的发现!
    猜你喜欢
    • 2018-08-11
    • 2020-04-16
    • 2019-01-24
    • 1970-01-01
    • 2020-09-16
    • 2017-05-08
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    相关资源
    最近更新 更多