Download and install MongoDB. You can set custom installation directory or let default location in "C:\Program Files\MongoDB\Server\<version>".
Add "C:\Program Files\MongoDB\Server\<version>\bin" to environment variable.
Create directory for database data and log data. For example, database is in "C:\mongodb\data\db\" and log is in "C:\mongodb\log\".
Create MongoDB configuration file. For example, it is in "C:\mongodb\mongod.conf".
systemLog: destination: file path: c:\mongodb\log\mongod.log logAppend: true storage: dbPath: c:\mongodb\data\db
(CAUTION: Use spaces, not tabs)
Start the server by:
$ mongod --config "C:\mongodb\mongod.conf"
OR install it as a Windows service
$ mongod --config "C:\mongodb\mongod.conf" --install
Then, start the service.
$ net start MongoDB
To stop the service.
$ net stop MongoDB
To remove the service after stoping the service.
$ mongod --remove
If you want to add REST support, you add this configuration.
net: bindIp: 127.0.0.1 port: 27017 http: enabled: true RESTInterfaceEnabled: true
You can also run the service without specific configuration file. You add configuration as parameters when running the server.
$ mongod --directoryperdb --dbpath "C:\mongodb\data\db" --logpath "C:\mongodb\log\mongodb.log" --logappend --rest --install
If you want custom service in Windows. You can use "sc.exe:
$ sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\<version>\bin\mongod.exe\" --service --config=\"C:\mongodb\mongod.conf\"" DisplayName= "MongoDB" start= "auto"
(CAUTION: Use space (" ") after "=" for sc.exe parameter value and "\" for escaping double quotes)
To remove the service after stopping the service
$ sc.exe delete MongoDB
Comments
Post a Comment