Running MongoDB as a service in Windows:
We can start the mongoDB service either using the mongod command using it in command prompt.
We can start a service of MongoDB so that the service will be running in the background.
Referring to the earlier mongoDB post, below is the steps to start the mongdb service.
Reference link : http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/
> sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB 2.6 Enterprise\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB 2.6 Enterprise\mongod.config\"" DisplayName= "MongoDB 2.6 Enterprise" start= "auto"
Will result in following output on successful execution
[SC] CreateService SUCCESS
Note: A space should be provided between the = and the text following it.
refer http://technet.microsoft.com/en-us/library/bb490995.aspx for help on the SC command.
Refer the snapshot below:
using the below commands:
> net start MongoDB
Refer the snapshot (figure 3) for the results of the command on successful execution.
> net start (this command will list the started service in windows)
The MongoDB 2.6 Enterprise service was started successfully.
Note MongoDB 2.6 Enterprise is the service display name we have input to create a service.
> net stop MongoDB
above command will stop the service which is running.
Once stopped, on trying to executing the command db, show dbs, etc. on the shell using mongo command will fail. Because the MonogDB service is not running.
To delete the created service.
> sc.exe delete MongoDB
Note the above command will delete the service that we have created. The service name is MongoDB so we need to use it here. Not the displayName used in the create service command.
Once the service is started open another command prompt using cmd in windows. And try the db operations. It will connect to the database and provide the appropriate outputs.
We can start the mongoDB service either using the mongod command using it in command prompt.
We can start a service of MongoDB so that the service will be running in the background.
Referring to the earlier mongoDB post, below is the steps to start the mongdb service.
Reference link : http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/
> sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB 2.6 Enterprise\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB 2.6 Enterprise\mongod.config\"" DisplayName= "MongoDB 2.6 Enterprise" start= "auto"
Will result in following output on successful execution
[SC] CreateService SUCCESS
Note: A space should be provided between the = and the text following it.
refer http://technet.microsoft.com/en-us/library/bb490995.aspx for help on the SC command.
Refer the snapshot below:
Figure 3
The above command creates a service. we can then start and stop the service:using the below commands:
> net start MongoDB
Refer the snapshot (figure 3) for the results of the command on successful execution.
> net start (this command will list the started service in windows)
The MongoDB 2.6 Enterprise service was started successfully.
Note MongoDB 2.6 Enterprise is the service display name we have input to create a service.
> net stop MongoDB
above command will stop the service which is running.
Once stopped, on trying to executing the command db, show dbs, etc. on the shell using mongo command will fail. Because the MonogDB service is not running.
To delete the created service.
> sc.exe delete MongoDB
Note the above command will delete the service that we have created. The service name is MongoDB so we need to use it here. Not the displayName used in the create service command.
Once the service is started open another command prompt using cmd in windows. And try the db operations. It will connect to the database and provide the appropriate outputs.

