Mongoose:“TypeError:”侦听器“参数必须是连接上的函数”

时间:2023-01-16 15:47:03

I'm trying to use Mongoose with typescript 2.2.1, express 4.15.2 and node v7.7.2 but when i try to connect to mongodb it throws this error:

我正在尝试使用Mongoose与typescript 2.2.1,表达4.15.2和节点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/f*/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/f*/Projects/Huis-Pils/node_modules/mongodb-core/lib/connection/connection.js:399:11)
at Pool.connect (/home/f*/Projects/Huis-Pils/node_modules/mongodb-core/lib/connection/pool.js:638:16)
at Server.connect (/home/f*/Projects/Huis-Pils/node_modules/mongodb-core/lib/topologies/server.js:384:17)
at Server.connect (/home/f*/Projects/Huis-Pils/node_modules/mongodb/lib/server.js:361:17)
at open (/home/f*/Projects/Huis-Pils/node_modules/mongodb/lib/db.js:226:19)
at Db.open (/home/f*/Projects/Huis-Pils/node_modules/mongodb/lib/db.js:249:44)
at NativeConnection.doOpen (/home/f*/Projects/Huis-Pils/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:58:11)
at NativeConnection.Connection._open (/home/f*/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:531:15)
at /home/f*/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:289:11
at new wrappedPromise (/home/f*/Projects/Huis-Pils/node_modules/async-listener/index.js:372:16)
at NativeConnection.Connection.open (/home/f*/Projects/Huis-Pils/node_modules/mongoose/lib/connection.js:288:17)
at Mongoose.connect (/home/f*/Projects/Huis-Pils/node_modules/mongoose/lib/index.js:242:47)

code:

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

i just can't figure out what i'm doing wrong.

我只是无法弄清楚我做错了什么。

1 个解决方案

#1


2  

I had similar issue and it can be bug of Node 7.7.2

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

If then, it should be solved by https://github.com/nodejs/node/pull/11762

如果那时,它应该通过https://github.com/nodejs/node/pull/11762解决

#1


2  

I had similar issue and it can be bug of Node 7.7.2

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

If then, it should be solved by https://github.com/nodejs/node/pull/11762

如果那时,它应该通过https://github.com/nodejs/node/pull/11762解决