Mongoose NodeJS macOS Big Sur MongooseServerSelectionError: connect ECONNREFUSED ::1:27017

Viewed 1729

I'm using brew mongodb-community on macOS Big Sur and can connect to mongo shell with mongosh. But when I try to run NodeJS and Mongoose app I get MongooseServerSelectionError: connect ECONNREFUSED ::1:27017. Why can I connect to mongodb with mongo shell but not NodeJS and Mongoose?

Edit: Sample code from my NodeJS Mongoose code

import mongoose from 'mongoose';
mongoose.connect('mongodb://localhost:27017/mydb', {
    useNewUrlParser: true,
    useUnifiedTopology: true
});
1 Answers

My solution was to use 127.0.0.1 and NOT localhost. For some reason Mongoose can read mongodb://127.0.0.1:27017/mydb and NOT mongodb://localhost:27017/mydb

Related