MongoDB Installation Process
To begin installation, download the appropriate MongoDB package from the official website based on your system architecture. Pre-compiled binaries are available for both 32-bit and 64-bit Windows systems:
- 64-bit version: Compatible with Windows Server 2008 R2, Windows 7, and newer versions
- 32-bit version: Suitable for older Windows systems including Vista, with a 2GB database size limitation
- Legacy 64-bit version: Designed for Windows Vista, Server 2003, and Server 2008
After downloading the .msi installer, proceed with the standard installation process. During setup, you may choose "Custom" installation to specify your preferred directory. It's recommended to skip MongoDB Compass installation during this step, as it can be installed separately later if needed.
Following installation, create the required data directories. MongoDB requires a dedicated folder structure for storing database files. Create these directories at the root level:
cd C:\
mkdir data\db
This can also be accomplished through Windows Explorer if command-line access is unavailable.
Starting MongoDB Server via Command Line
To launch the MongoDB server manually, navigate to the installation's bin directory and execute the server binary with the data path parameter:
C:\mongodb\bin\mongod --dbpath c:\data\db
The server will display startup information including version details, port configuration, and system compatibility checks.
Establishing Database Connection
Connect to the running MongoDB instance by executing the client application from the bin directory:
C:\mongodb\bin\mongo.exe
Service Configuration Setup
Newer MongoDB versions often handle service configuration automatically. If the required directories already exist, this section can be skipped. For manual setup, open an elevated command prompt and create the necessary directories:
mkdir c:\data\db
mkdir c:\data\log
Create a configuration file at C:\mongodb\mongod.cfg with the following content:
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
Service Registration and Management
Register MongoDB as a Windows service using the configuration file:
C:\mongodb\bin\mongod.exe --config "C:\mongodb\mongod.cfg" --install
Control the service using standard Windows commands:
net start MongoDB
net stop MongoDB
To remove the service registration:
C:\mongodb\bin\mongod.exe --remove
Either the manual server execution or service-based approach can be used to run MongoDB.
MongoDB Administrative Interface
The MongoDB Shell provides an interactive JavaScript environment for database administration. Launch it by running mongo.exe from the installation's bin directory. Upon connection, the shell defaults to the 'test' database:
> mongo
MongoDB shell version: 3.0.6
connecting to: test
As a JavaScript environment, basic arithmetic operations are supported:
> 2 + 2
4
View the current database context:
> db
test
Perform basic document operations by inserting records and querying collections:
> db.collection_name.insert({field: value})
> db.collection_name.find()