请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

连接docker出问题,尝试了多种方法还是不行:MongoDB连接异常

MongoDB连接异常: MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1054:14) {
name: ‘MongoNetworkError’,
[Symbol(mongoErrorContextSymbol)]: {}

正在回答 回答被采纳积分+3

3回答

李嘉图principal 2023-03-29 12:56:11

mongo-express版本问题,前面用了mongo版本4后面express却默认用最新版本

docker run --link mymongo:mongo p 8081:8081 mongo-express:0.54.0


0 回复 有任何疑惑可以回复我~
提问者 HH2019 2020-04-05 04:53:18

执行的命令为node app.js,股票那个项目,保存信息就是上面的,很长但内容重复,我估计是连不上Docker的mogondb

报错:

henry@MSI:/mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService$ node app.js

(node:2374) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnified

Topology: true } to the MongoClient constructor.

仓位记录管理服务运行中...

MongoDB连接异常: MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017

    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) {

  name: 'MongoNetworkError',

  [Symbol(mongoErrorContextSymbol)]: {}

}]

    at Pool.<anonymous> (/mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/topologies/server.js:438:11)

    at Pool.emit (events.js:311:20)

    at /mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/connection/pool.js:561:14

    at /mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/connection/pool.js:994:11

    at /mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/connection/connect.js:31:7

    at callback (/mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/connection/connect.js:264:5)

    at Socket.<anonymous> (/mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/connection/connect.js:294:7)

    at Object.onceWrapper (events.js:418:26)

    at Socket.emit (events.js:311:20)

    at emitErrorNT (internal/streams/destroy.js:92:8)

    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)

    at processTicksAndRejections (internal/process/task_queues.js:84:21) {

  name: 'MongoNetworkError',

  [Symbol(mongoErrorContextSymbol)]: {}

}

(node:2374) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017

    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) {

  name: 'MongoNetworkError',

  [Symbol(mongoErrorContextSymbol)]: {}

}]

    at Pool.<anonymous> (/mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/topologies/server.js:438:11)

    at Pool.emit (events.js:311:20)

    at /mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/connection/pool.js:561:14

    at /mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/connection/pool.js:994:11

    at /mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/connection/connect.js:31:7

    at callback (/mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/connection/connect.js:264:5)

    at Socket.<anonymous> (/mnt/c/Users/hxl20/Desktop/Public/mogonDB/PositionService/node_modules/mongodb/lib/core/connection/connect.js:294:7)

    at Object.onceWrapper (events.js:418:26)

    at Socket.emit (events.js:311:20)

    at emitErrorNT (internal/streams/destroy.js:92:8)

    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)

    at processTicksAndRejections (internal/process/task_queues.js:84:21)

(node:2374) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handle

d with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1

)

(node:2374) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


0 回复 有任何疑惑可以回复我~
  • Stannum #1
    同学,你可以尝试以下的操作:
    1. 确认你的mongod进程在docker容器中是运行的状态。看看能否正常连接到mongo shell
    2. 检查一下你的防火墙配置是否影响了连接
    3. 检查一下你的/etc/hosts文件里面是否有不必要的域名设置
    回复 有任何疑惑可以回复我~ 2020-04-12 18:05:35
Stannum 2020-04-04 22:16:45

同学好~可不可以把你执行的命令和完整的错误信息也发出来看一下?

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信