Node.js failing to connect to MongoDB

前端 未结 1 1765
南笙
南笙 2021-01-22 02:25

I am new to both Node.js and MongoDB. I am following this guide: http://howtonode.org/express-mongodb to create a simple blog with Node.js and MongoDB.

When node tries t

相关标签:
1条回答
  • 2021-01-22 02:55

    That happens when the mongod process is not running or you're connecting to the wrong host/ip.

    Do you have it running on your localhost and if so can you access it from your from the mongo shell?

    Try to test it with a minimum version of an app with node, express and the mongodb nodejs driver.

    I tested it with these files:

    • http://howtonode.org/express-mongodb/articleprovider-mongodb.js
    • http://howtonode.org/express-mongodb/app.js

    And it worked fine, except for the last two lines of app.js, because of express 3.x instead of 2.x used in the example.

    var server = app.listen(3000);
    console.log("Express server listening on port %d in %s mode", server.address().port, app.settings.env);
    
    0 讨论(0)
提交回复
热议问题