MongoDB
Windows
Database
Installation
Startup

How do I start Mongo DB from Windows?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Starting MongoDB on Windows is usually a matter of locating mongod.exe, creating a valid data directory, and deciding whether you want a foreground process or a Windows service. Most startup failures come from ordinary setup issues such as missing folders, wrong binary paths, or a service configuration that was never tested manually first.

Verify the Installation Path First

Before you debug startup, confirm that the MongoDB binaries are actually where you think they are. A standard installation often places them under a versioned directory in Program Files.

powershell
Get-ChildItem "C:\Program Files\MongoDB\Server" -Directory
& "C:\Program Files\MongoDB\Server\7.0\bin\mongod.exe" --version
& "C:\Program Files\MongoDB\Server\7.0\bin\mongosh.exe" --version

If those commands fail, the problem is installation or path selection, not database startup logic.

Start mongod Manually First

The most reliable first test is manual startup in a terminal window. Create the data directory if it does not exist:

powershell
New-Item -ItemType Directory -Force -Path C:\data\db | Out-Null

Then run the server directly:

powershell
& "C:\Program Files\MongoDB\Server\7.0\bin\mongod.exe" `
  --dbpath "C:\data\db" `
  --port 27017

Keep that terminal open. When the window closes, the foreground server process stops.

In a second PowerShell window, test the shell connection:

powershell
& "C:\Program Files\MongoDB\Server\7.0\bin\mongosh.exe" --port 27017

Then run a quick health check:

javascript
db.adminCommand({ ping: 1 })

If this works, you know the database itself can start successfully.

Use a Config File for Repeatable Startup

Command-line startup is good for verification, but a config file is easier to maintain.

Example mongod.cfg:

yaml
1storage:
2  dbPath: C:\data\db
3systemLog:
4  destination: file
5  path: C:\data\log\mongod.log
6  logAppend: true
7net:
8  bindIp: 127.0.0.1
9  port: 27017

Create the log folder too:

powershell
New-Item -ItemType Directory -Force -Path C:\data\log | Out-Null

Then start with the config file:

powershell
& "C:\Program Files\MongoDB\Server\7.0\bin\mongod.exe" --config "C:\mongodb\mongod.cfg"

This approach is easier to reuse and document than a long command copied from memory.

Run MongoDB as a Windows Service

For everyday development, a Windows service is often more convenient than a foreground terminal process.

Install the service:

powershell
& "C:\Program Files\MongoDB\Server\7.0\bin\mongod.exe" `
  --config "C:\mongodb\mongod.cfg" `
  --install

Then start and inspect it:

powershell
Start-Service MongoDB
Get-Service MongoDB

To stop it later:

powershell
Stop-Service MongoDB

If the service starts and then immediately stops, check the configured log file and Windows Event Viewer before changing settings blindly.

Confirm That It Is Actually Listening

Do not stop at the process list. Verify that the database is listening on the expected port.

powershell
Get-Process mongod -ErrorAction SilentlyContinue
netstat -ano | findstr 27017

If the process exists but the shell cannot connect, the likely causes are bind settings, a port conflict, or a local firewall rule.

As a quick diagnostic, try another port temporarily:

powershell
& "C:\Program Files\MongoDB\Server\7.0\bin\mongod.exe" `
  --dbpath "C:\data\db" `
  --port 27018

That helps separate "MongoDB cannot start" from "something else is already using 27017."

Common Pitfalls

A common mistake is starting mongod before creating the configured dbPath. MongoDB cannot use a data directory that does not exist.

Another issue is hardcoding an old versioned path and forgetting to update it after reinstalling or upgrading MongoDB.

Developers also sometimes close the terminal that launched a manual mongod process and then assume the database is still running. Foreground startup only lasts as long as that window remains open.

Summary

  • Verify the MongoDB installation path before troubleshooting startup.
  • Create the data directory before running mongod.
  • Start MongoDB manually first so direct errors are visible.
  • Use a config file and Windows service mode for a repeatable local setup.
  • Check logs, port listeners, and shell connectivity when startup fails.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.