In this tutorial, we will show you how to start the MongoDB server with some command line options on Windows.
What We Used
- Microsoft Windows 7
- MongoDB 3.2.9
Start MongoDB without Command Line Options
We can start MongoDB server without any command line options by executing the following command in Command Prompt window:
mongod
MongoDB server will be started with the following default settings:
- Store data in data directory
C:\data\db
- Listen to port
27017
for new connections - Print out the logs on console
Listen to Different Port
You can start the MongoDB server to listen to different port number for connections.
mongod --port 27018
Store Data to Different Directory
You can specify the MongoDB server to store the database data in different data directory.
mongod --dbpath C:\mongodb\data\db
Write Logs to File
You can specify the MongoDB server to write the logs to a log file.
mongod --logpath C:\mongodb\logs\mongodb.log
Limit Data File Size
For development purpose, you can reduce the initial data files size of MongoDB server and limit the maximum data files size up to 512MB with --smallfiles
option. This option also can reduce the maximum file size of each journal files from 1GB to 128MB.
mongod --smallfiles
Note: --smallfiles
option is not recommended for production server.
Start MongoDB with Command Line Options
You can start the MongoDB server with all above options in one command line.
mongod --port 27018 --dbpath C:\mongodb\data\db --logpath C:\mongodb\logs\mongodb.log --smallfiles
Tip: If you have too many options required to start the MongoDB server, it is recommended to use configuration file rather than command line options.
Summary
Congratulation! You have learned how to start MongoDB server with command line options on Windows.