无法使用mongoose进行端口转发

时间:2018-03-05 16:34:45

标签: node.js mongodb mongoose

我正在尝试将本地端口绑定到远程mongo端口,因为无法从本地直接访问远程服务器。我正在尝试像这样的SSH端口绑定。

ssh -L 27017:localhost:27017 <remote server>

当我尝试使用mongo mongodb://localhost:27017在本地打开mongo shell时。 mongo连接到远程服务器,但是当我使用mongoose从节点应用程序执行相同操作时。我收到连接错误。有人可以建议系统级解决这个问题。

Something broke!!! - MongoError: failed to connect to server [server1:27017] on first connect [MongoError: getaddrinfo ENOTFOUND server1 server1:27017]
    at null.<anonymous> (/home/user1/src/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:336:35)
    at emitOne (events.js:77:13)
    at emit (events.js:169:7)
    at null.<anonymous> (/home/user1/src/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:280:12)
    at g (events.js:260:16)
    at emitTwo (events.js:87:13)
    at emit (events.js:172:7)
    at Socket.<anonymous> (/home/user1/src/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:187:49)
    at Socket.g (events.js:260:16)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at connectErrorNT (net.js:1016:8)
    at nextTickCallbackWith2Args (node.js:511:9)
    at process._tickCallback (node.js:425:17)

0 个答案:

没有答案