Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

node.js - Mongoose Can't Connect Without Internet

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]

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?

EDIT: here is the error in full

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...

Edit: wording

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...