MongoDB exception:connection failed

时间:2023-03-09 01:12:33
MongoDB exception:connection failed

根据http://www.runoob.com/mongodb/mongodb-window-install.html的教程配置了MongoDB,Mongod.exe配置为

MongoDB exception:connection failed

--port 指令表明mongo指向的端口,配置完启用服务后,提示异常

connect@src/mongo/shell/mongo.js:237:13

@(connect):1:6

exception: connect failed

MongoDB exception:connection failed

异常显示连接到端口27017失败,此端口为默认MongoDB默认端口,并非在mongod中配置端口,这表明运行的mongo服务未启用指定的端口。

解决此异常的方法是,指定mongod配置文件

MongoDB exception:connection failed

config的配置为:

systemLog:
    destination: file
    path: c:\data\dblog\mongodb.log
    logAppend: true
storage:
    journal:
        enabled: true
    dbPath: c:\data\db
net:
    port: 你指定的端口

然后重新配置mongod.exe,启动服务,这时再运行mongo --port 你指定的端口,运行结果为:

MongoDB exception:connection failed

这时表明MongoDB配置成功。