Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I need to be able to start/stop MongoDB on the CLI. It is quite simple to start:

./mongod

But to stop mongo DB, I need to run open mongo shell first and then type two commands:

$ ./mongo

use admin

db.shutdownServer()

So I don't know how to stop mongo DB in one line. Any help?

2 Answers

0 votes
by (106k points)

To stop MongoDB in one command you literally want a one-line equivalent to the commands in your original question, you could alias:

mongo --eval "db.getSiblingDB('admin').shutdownServer()"

0 votes
by (108k points)

If you want to stop MongoDB in a single command, use the following syntax:

mongo --eval "db.getSiblingDB('admin').shutdownServer()"

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
0 votes
2 answers
0 votes
1 answer

Browse Categories

...