Categories
JavaScript Answers

How to fix MongoNetworkError: failed to connect to server [localhost:27017] on first connect with Node MongoDB?

Spread the love

To fix MongoNetworkError: failed to connect to server [localhost:27017] on first connect with Node MongoDB, we should make sure we’re connecting to a reachable Mongo server.

For instance, we write

await mongoose.connect("mongodb://localhost/testdb");

to call mongoose.connect to connect to the testdb database on localhost.

The error shouldn’t be thrown if it’s reachable.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.