Mongoose 无法在没有 Internet 的情况下连接 [英] Mongoose Can't Connect Without Internet

查看:29
本文介绍了Mongoose 无法在没有 Internet 的情况下连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 MongoDB 服务器在 localhost:27017 上运行,虽然我通常可以正常运行我的 Node.js 应用程序,但当我断开互联网连接时 Mongoose 会抛出错误

I have my MongoDB server running on localhost:27017, and while I can usually run my Node.js app fine, when I disconnect from the internet Mongoose throws the error

Error: failed to connect to [localhost:27017]

请注意,我仍然可以从 Mongo shell 客户端连接到 MongoDB 服务器.此外,如果我先启动我的应用程序然后失去互联网连接,我的应用程序可以很好地离线访问数据库.那么为什么它不能在没有互联网的情况下启动?

Note that I can still connect to the MongoDB server from the Mongo shell client. Also, if I start up my app first and then lose internet connection, my app can access the database fine offline. So why can't it start up without internet?

这里是完整的错误

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: failed to connect to [localhost:27017]
    at null.<anonymous> (<My App>
ode_modulesmongoose
node_modulesmongodblibmongodbconnectionserver.js:555:74)
    at emit (events.js:118:17)
    at null.<anonymous> (<My App>
ode_modulesmongoose
node_modulesmongodblibmongodbconnectionconnection_pool.js:156:15)
    at emit (events.js:110:17)
    at Socket.<anonymous> (<My App>
ode_modulesmongoos
e
ode_modulesmongodblibmongodbconnectionconnection.js:534:10)
    at Socket.emit (events.js:107:17)
    at net.js:923:16
    at process._tickCallback (node.js:355:11)
[nodemon] app crashed - waiting for file changes before starting...

措辞

推荐答案

使用 127.0.0.1 而不是 localhost.通过关闭您的 wifi 接口,操作系统不再能够解析本地主机.

Use 127.0.0.1 instead of localhost. By turning off your wifi interface the OS is no longer able to resolve localhost.

这篇关于Mongoose 无法在没有 Internet 的情况下连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆