2

According to MongoDB documentation,when running mongodb community edition, it states you can start mongo service using mongod, or net start MongoDB.

Either is required to access the mongo shell.

Can someone explain the difference between using mongod and net start MongoDB

3 Answers 3

1

You can always run mongod with a command. But if you decide to run mongod as a Windows service, in first step you need to set up a service by running mongod with --install option:

"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\3.4\mongod.cfg" --install

Then, you can use net start/stop to use the installed service:

net start MongoDB
2
  • What's the difference running it as a service with net start MongoDB compared to with the command mongod
    – nathphan
    Commented Oct 17, 2017 at 0:21
  • No difference except that you can config a service to start at Windows boot.
    – anhlc
    Commented Oct 17, 2017 at 0:28
1

These are the different names of the services for running mongodb. You can start it as sudo service mongod start OR sudo service mongodb start based on which service you got on your machine while installing mongodb.

If you have both of these services on your machine, you need to check which should be started by checking the content of that file itself and remove another if required.

mongod is the service name that comes default when you install mongodb using package manager on ubuntu.

In your case net start MongoDB will start the mongodb service.

1
  • 1
    Question maker uses windows not linux..
    – JJussi
    Commented Oct 17, 2017 at 9:17
1

Difference between net start MongoDB and mongod

As simple we can say that mongod is to start MongoDB Server in Linux Environment & net start MongoDB is to start MongoDB Server is in Windows Environment. If as per MongoDB documeatation For Windows Environment and For Linux Environment there will be config file , data path and log path as default configuration.

As MongoDB Documentation Starting in MongoDB 3.6, MongoDB binaries, mongod and mongos, bind to localhost by default. Previously, starting in MongoDB 2.6, only the binaries from the official MongoDB RPM (Red Hat, CentOS, Fedora Linux, and derivatives) and DEB (Debian, Ubuntu, and derivatives) packages bind to localhost by default.

To Run MongoDB in Linux Environment

To run MongoDB, run the mongod process at the system prompt. If necessary, specify the path of the mongod or the data directory. See the following examples.

Run without specifying paths

If your system PATH variable includes the location of the mongod binary and if you use the default data directory (i.e., /data/db), simply enter mongod at the system prompt:

mongod

Specify the path of the mongod

If your PATH does not include the location of the mongod binary, enter the full path to the mongod binary at the system prompt:

<path to binary>/mongod

Specify the path of the data directory

If you do not use the default data directory (i.e., /data/db), specify the path to the data directory using the --dbpath option:

mongod --dbpath <path to data directory>

Begin using MongoDB

Start a mongo shell on the same host machine as the mongod. Use the --host command line option to specify the localhost address and port that the mongod listens on:

mongo --host 127.0.0.1:27017

Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

To Run MongoDB in Windows Environment

For example, create a file at C:\Program Files\MongoDB\Server\3.6\mongod.cfg that specifies both systemLog.path and storage.dbPath:

systemLog:
    destination: file
    path: c:\data\log\mongod.log
storage:
    dbPath: c:\data\db

And you have Install the MongoDB service in below configuration

"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\3.6\mongod.cfg" --install

The you shall able to start the MongoDB service with the below command

net start MongoDB

The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mongo shell to query and update data as well as perform administrative operations.

For your further ref here, here and here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.