DEV Community

Cover image for Fixing “MongoDB Service Not Starting (Error 1067)” on Windows
Subhro
Subhro

Posted on

Fixing “MongoDB Service Not Starting (Error 1067)” on Windows

If you’ve been working with MongoDB locally and suddenly see this dreaded error:

connect ECONNREFUSED 127.0.0.1:27017
connect ECONNREFUSED ::1:27017

or this one in your Command Prompt:

The MongoDB Server (MongoDB) service could not be started.
A system error has occurred.
System error 1067 has occurred.
The process terminated unexpectedly.

you’re not alone — this happens to almost every developer at least once.
Let’s go step by step through why it happens and how to fix it once and for all.

Understanding the Problem

Your Node.js app (or mongosh) is trying to connect to the MongoDB server running locally on port 27017.
The “ECONNREFUSED” error means MongoDB isn’t listening on that port — because it never started properly.

When you try to start it manually via:
net start MongoDB

and get System Error 1067, it means the MongoDB Windows service crashed during startup.

Step 1 — Locate the Configuration File

MongoDB uses a configuration file (mongod.cfg) to know where to store data and logs.

To find it, run:
sc qc MongoDB

Look for the line:
BINARY_PATH_NAME : "C:\Program Files\MongoDB\Server\8.2\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\8.2\bin\mongod.cfg"

Copy the path after --config. That’s the file you’ll edit.

Step 2 — The Most Common Cause: Wrong dbPath Location

Inside your mongod.cfg, you’ll see something like:
storage:
dbPath: C:\Program Files\MongoDB\Server\8.2\data
systemLog:
destination: file
logAppend: true
path: C:\Program Files\MongoDB\Server\8.2\log\mongod.log

That’s the default, but there’s a catch 👇

C:\Program Files\ is a protected directory in Windows.
MongoDB runs as a service user (Network Service) that does not have permission to write there — so it crashes instantly.

Step 3 — Move the Data and Log Folders

The safest fix is to move them outside Program Files.

  1. Open Command Prompt (Admin) and create folders:
    mkdir C:\data\db
    mkdir C:\data\log

  2. Open your mongod.cfg and update the paths:
    storage:
    dbPath: C:\data\db
    systemLog:
    destination: file
    logAppend: true
    path: C:\data\log\mongod.log
    net:
    port: 27017
    bindIp: 127.0.0.1

Save the file.

Step 4 — Restart MongoDB Service

Now restart MongoDB:
net start MongoDB

You should see:
The MongoDB Server (MongoDB) service was started successfully.

That’s it — MongoDB is back online! ✅

You can confirm by running:
mongosh

If you get a prompt like:
test>

your local MongoDB instance is working perfectly.

Step 5 — If It Still Fails

Check the log file defined in your config:
C:\data\log\mongod.log

The last few lines will tell you exactly what went wrong — common issues include:

  • Missing data directory
  • Permission errors
  • Wrong YAML indentation
  • Another process already using port 27017

Alternative Fix — Grant Permissions (Not Recommended)

If you absolutely need to keep MongoDB data inside Program Files, you can give permissions manually:
icacls "C:\Program Files\MongoDB\Server\8.2\data" /grant "Network Service":(OI)(CI)F
icacls "C:\Program Files\MongoDB\Server\8.2\log" /grant "Network Service":(OI)(CI)F

Then restart:
net start MongoDB

However, it’s cleaner and safer to use C:\data\db instead.

Conclusion

If MongoDB won’t start on Windows and you see System error 1067 or ECONNREFUSED 27017,
the problem almost always comes down to file permissions or incorrect paths in your configuration.

By moving your data and logs to:
C:\data\db
C:\data\log

and updating your mongod.cfg, you’ll fix the issue permanently.

Top comments (0)