Reputation: 13343
The official MongoDB documentation says:
Issue the following command to start mongod:
sudo service mongod start
However, the reputable MongoDB: The Definitive Guide, 2nd Edition says on page 11 that:
To start the server, run the mongod executable:
$ mongod
On my Ubuntu 16.04 system the first one runs ok, and the second one runs after I create the /data/db
directory and change its permissions or run with sudo mongod
.
I was wondering, when should you use which manner? Aside from the minor difference that the second way grabs the terminal.
sudo service mongod start
vs
mongod
I tried to look up what the service
command does, but the documentation is too advanced for me.
Upvotes: 3
Views: 1291
Reputation: 9517
There are quite a few advantages to running MongoDB as a service vs. just starting the mongod process from the command line. I generally prefer to start mongod from the command line when I'm running locally on my laptop, but for any kind of deployment to a real server in dev, qa, production, etc. I always recommend to run it as a service.
Here are some of the reasons:
It's also worth noting that you can still start mongod from the command line and use a config file, and if you specify the "fork" option it won't "grab" your terminal.
Upvotes: 5