MongoDB errors
-
MongoDB
Fix MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
ECONNREFUSED means nothing is listening where Mongoose is trying to connect. Start MongoDB (sudo systemctl start mongod, or brew services start mongodb-community on macOS), and if the error mentions ::1:27017, change localhost to 127.0.0.1 in your connection string. In Docker, use the database service name instead of localhost.
-
MongoDB
Fix MongoDB E11000 Duplicate Key Error (Mongoose Guide)
E11000 means an insert or update would create two documents with the same value in a field that has a unique index. Read the index name and dup key in the message. If it is a real duplicate, return a 409 error to the user. If the value is null, use a partial index; if the index is left over from an old schema, drop it with db.collection.dropIndex().


