-1

After trying to connect to my MongoDB database while testing my code in Node.js as per usual, I received a connect ECONNREFUSED 127.0.0.1:27017, connect ECONNREFUSED ::1:27017 error message in console. When opening MongoDB Compass and trying to connect to it there, I also got the same message.

When looking at solutions online, one of them said to try going to C:\Program Files\MongoDB\Server\8.0\bin and there run the mongod.exe. Which worked and I could connect to my database, however 1. it only works after manually doing this process, and only until the mongod.exe console is kept open, even though before I needed neither of these things and more importantly 2. my whole database seems wiped?? Only the original admin, local, and config databases are there.

What's going on? The day before I turned off the computer forcefully with the power button after Excel froze on me, does that have to do anything with this? I have no other idea, what could have happened. Can I recover my database or do I need to load in all the data again?

1
  • Please provide enough code so others can better understand or reproduce the problem.
    – Community Bot
    Commented Feb 6 at 18:59

1 Answer 1

0

When you run C:\Program Files\MongoDB\Server\8.0\bin\mongod.exe then MongoDB uses the default database at \data\db on current drive.

However, when MongoDB is started as service, then (most likely) MongoDB reads the configuration file where by default dbPath is set to C:\Program Files\MongoDB\Server\8.0\data\ (see What is the default database path for MongoDB?)

So, it looks like you open two different location of data, thus most likely your database is not deleted. You must open the correct data folder!

Regarding your actual error connect ECONNREFUSED ::1:27017, see Can't connect to MongoDB 6.0 Server locally using Node.js driver and/or MongooseServerSelectionError: connect ECONNREFUSED ::1:27017

1
  • Well, that just means I haven't made any progress. How does it even happen that I can't connect from one day to another with the same connection uri to my database, when I changed nothing? Commented Feb 6 at 14:17

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.