最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

MongoDB connect ECONNREFUSED error into having my database deleted? - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question asked Feb 6 at 9:32 user28751094user28751094 11 bronze badge 1
  • Please provide enough code so others can better understand or reproduce the problem. – Community Bot Commented Feb 6 at 18:59
Add a comment  | 

1 Answer 1

Reset to default 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

发布评论

评论列表(0)

  1. 暂无评论