How to Install MongoDB on Windows Server 2022
MongoDB is a leading NoSQL document database that stores data in flexible, JSON-like BSON documents. Installing MongoDB Community Server on Windows Server 2022 and configuring it properly for production involves several steps: running the MSI installer, configuring the mongod.cfg file, enabling authentication, creating administrative users, and establishing backup routines. This guide covers the complete process from download to a secured, remotely accessible MongoDB instance.
Downloading MongoDB Community Server
Go to the MongoDB download center at https://www.mongodb.com/try/download/community and select the following options: Version (6.0 or 7.0), Platform (Windows), and Package (MSI). Download the MSI installer. The filename will be something like mongodb-windows-x86_64-7.0.6-signed.msi. Transfer the installer to your Windows Server 2022 machine.
MongoDB also offers MongoDB Tools (mongodump, mongorestore, mongostat, etc.) as a separate download — grab the MongoDB Database Tools MSI from the same download page under Tools. Download MongoDB Shell (mongosh) as well, since it replaces the legacy mongo shell in all recent MongoDB versions.
Running the MSI Installer
Right-click the MSI and choose Install. The installation wizard will launch. On the Choose Setup Type screen, select Complete to install all components including MongoD, the client tools, and the Compass GUI option. On the Service Configuration screen, check the box for Install MongoD as a Service. Set the service name to MongoDB, the data directory to C:datadb, and the log directory to C:datalog. The installer will create these directories.
On the Install MongoDB Compass screen, leave it checked to install the Compass GUI. Click Install to proceed. Once complete, MongoDB will be running as a Windows service.
Verifying the MongoDB Service
Open PowerShell as Administrator and check the service status:
Get-Service -Name "MongoDB"
The service should show as Running. Manage it with standard service commands:
Stop-Service -Name "MongoDB"
Start-Service -Name "MongoDB"
Restart-Service -Name "MongoDB"
The service starts automatically on boot by default. The MongoDB process (mongod.exe) reads its configuration from C:Program FilesMongoDBServer7.0binmongod.cfg.
Understanding mongod.cfg
The mongod.cfg file uses YAML format. Open it with a text editor running as Administrator. The default content looks like this:
systemLog:
destination: file
path: C:datalogmongod.log
logAppend: true
storage:
dbPath: C:datadb
journal:
enabled: true
net:
port: 27017
bindIp: 127.0.0.1
processManagement:
windowsService:
serviceName: MongoDB
displayName: MongoDB
This default configuration binds only to localhost (127.0.0.1), which means remote connections are not yet possible. Authentication is also not enabled — we will address both shortly.
Enabling Authentication
MongoDB’s access control is disabled by default. Before enabling it, you must first create an administrative user. Connect using mongosh (no authentication required yet):
mongosh --port 27017
Switch to the admin database and create a root user:
use admin
db.createUser({
user: "adminUser",
pwd: "SecureAdminPass123!",
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" },
{ role: "dbAdminAnyDatabase", db: "admin" },
{ role: "clusterAdmin", db: "admin" }
]
})
Exit mongosh with exit. Now edit mongod.cfg to enable authentication:
security:
authorization: enabled
Restart the MongoDB service:
Restart-Service -Name "MongoDB"
Now connect with authentication:
mongosh --port 27017 -u adminUser -p SecureAdminPass123! --authenticationDatabase admin
Creating Application Databases and Users
Never use the root admin user for application connections. Create a dedicated user for each application database:
use appdb
db.createUser({
user: "appUser",
pwd: "AppUserPass456!",
roles: [
{ role: "readWrite", db: "appdb" }
]
})
Test application-level connectivity:
mongosh --port 27017 -u appUser -p AppUserPass456! --authenticationDatabase appdb
Enabling Remote Access
To allow remote connections, change the bindIp setting in mongod.cfg. You can bind to a specific IP address or to all interfaces:
net:
port: 27017
bindIp: 0.0.0.0
Using 0.0.0.0 binds to all interfaces. For tighter security, specify only the network interface IP that application servers will use, for example 192.168.1.50. Restart the service after editing:
Restart-Service -Name "MongoDB"
Opening Windows Firewall Port 27017
Allow inbound TCP connections on port 27017 through Windows Firewall:
New-NetFirewallRule -DisplayName "MongoDB 27017" `
-Direction Inbound `
-Protocol TCP `
-LocalPort 27017 `
-Action Allow `
-Profile Domain,Private
Test the port from a remote machine:
Test-NetConnection -ComputerName 192.168.1.50 -Port 27017
Basic MongoDB CRUD Operations
Connect to your application database and run basic operations using mongosh:
use appdb
// Insert a document
db.users.insertOne({ name: "Alice", email: "[email protected]", age: 30 })
// Insert multiple documents
db.users.insertMany([
{ name: "Bob", email: "[email protected]", age: 25 },
{ name: "Carol", email: "[email protected]", age: 35 }
])
// Find all documents
db.users.find()
// Find with filter
db.users.find({ age: { $gte: 30 } })
// Update a document
db.users.updateOne(
{ name: "Alice" },
{ $set: { age: 31 } }
)
// Delete a document
db.users.deleteOne({ name: "Bob" })
// Count documents
db.users.countDocuments()
// Create an index
db.users.createIndex({ email: 1 }, { unique: true })
Using MongoDB Compass
MongoDB Compass provides a graphical interface for exploring and managing your MongoDB data. Launch it from the Start menu. On the connection screen, enter the connection string. For a local authenticated instance:
mongodb://adminUser:SecureAdminPass123!@localhost:27017/?authSource=admin
Compass displays all databases and collections in the left panel. You can browse documents, run queries with a visual filter builder, view and create indexes, analyze schema structure, and run aggregation pipelines through its visual pipeline builder. The Performance tab shows real-time server metrics including operation counts, memory usage, and connection statistics.
Backup with mongodump and mongorestore
MongoDB Tools provides mongodump for logical backups. Dump a specific database:
mongodump --host localhost --port 27017 `
-u adminUser -p SecureAdminPass123! `
--authenticationDatabase admin `
--db appdb `
--out C:Backupsmongodump
This creates C:Backupsmongodumpappdb containing BSON files for each collection. Restore from the dump:
mongorestore --host localhost --port 27017 `
-u adminUser -p SecureAdminPass123! `
--authenticationDatabase admin `
--db appdb `
C:Backupsmongodumpappdb
For a full cluster dump (all databases):
mongodump --host localhost --port 27017 `
-u adminUser -p SecureAdminPass123! `
--authenticationDatabase admin `
--out C:Backupsmongodump_full
MongoDB Atlas Migration Overview
MongoDB Atlas is the fully managed cloud version of MongoDB. If you plan to migrate your on-premises Windows Server MongoDB instance to Atlas, the general workflow is: create an Atlas cluster (M10 or higher for production) in the Atlas portal, enable network peering or IP whitelist for your server IP, then use mongomirror or the Atlas Live Migration service for a zero-downtime cutover. For simpler scenarios with acceptable downtime, use mongodump to back up the source, then mongorestore to an Atlas cluster via its provided connection string. Atlas connection strings use the mongodb+srv:// protocol and include the cluster hostname, for example:
mongorestore --uri "mongodb+srv://adminUser:[email protected]/" `
--db appdb `
C:Backupsmongodumpappdb
Performance Tuning Notes
A few key configuration settings to tune in mongod.cfg for production workloads. The WiredTiger storage engine (the default since MongoDB 3.2) caches data in memory. By default, it uses 50% of RAM minus 1 GB. Set it explicitly:
storage:
wiredTiger:
engineConfig:
cacheSizeGB: 4
For write-heavy workloads, ensure journaling is enabled (it is by default). Enable slow operation logging to identify queries that need indexes:
operationProfiling:
slowOpThresholdMs: 100
mode: slowOp
View profiling data in the system.profile collection of any database, and use db.collection.explain(“executionStats”).find({…}) in mongosh to analyze query execution plans.
Summary
Installing MongoDB on Windows Server 2022 involves running the MSI installer to register the service, configuring mongod.cfg for data paths and network binding, enabling access control and creating administrative and application users, opening the firewall on port 27017, and establishing backup routines with mongodump. MongoDB Compass provides a powerful GUI for day-to-day administration. With authentication enabled and appropriate user roles, a MongoDB instance on Windows Server 2022 is ready to serve as a reliable document store for modern applications.