nodejs 连接mongodb时提示Cannot read property ‘DEFAULT_PORT’ of undefined

作者: 淡蓝海域 分类: Nodejs 发布时间: 2018-03-21 07:58

启动服务的时候, 在db.js中报错:

module.exports = new Db(settings.db, new Server(, Connection.DEFAULT_PORT, {}));
Cannot read property ‘DEFAULT_PORT’ of undefined。



Hello. I’ve checked this problem.

“Connection” form lib of “mongodb” has been removed in the latest version 2.0.42. When I created this project, mongodb version is 0.9.x. So you can set DEFAULT_PORT by your own.

I have updated the project. And in fact I set this argument in “./setting.js”. Usually the port of connection to mongodb is 27017. It depends.

At last, do not foget booting up your Mongodb and read it’s log. The log is the important road to lead everythings to be fine.


“mongodb”的“Connection”形式的lib在最新版本2.0.42中已被删除。 当我创建这个项目时,mongodb版本是0.9.x. 所以可以自己设置DEFAULT_PORT。

通常连接到mongodb的默认端口是27017。所以可以直接改成 27017 !