Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the mongo shell work without mongod server being explicitly run?

Running MongoDB Shell v-3.2.8

I've noticed that articles and tutorials always mention to run the mongod server before running the mongo shell.

However, when I skip the first step and simply type mongo into my terminal, the mongo shell works without any errors / interruptions.

MacBook:Desktop user$ mongo
MongoDB shell version: 3.2.8
connecting to: test

Why does this work? Does mongo call mongod?

like image 867
g.delgado Avatar asked Oct 27 '25 10:10

g.delgado


1 Answers

The mongod is being ran as a service or daemon, which means that there is always a mongod process running listening to a port. I use ubuntu, and when I install mongodb through the package manager, it immediately starts up a mongod process and begins listening on the standard port.

Running mongo is simply a small utility that attempts to connect to the localhost at the standard ip. The data reading, writing, and querying is done by the mongod process while mongo is a small program that sends the the commands to mongod.

If mongod wasn't running, you would see an error stating "Unable to connect to mongodb server"

like image 124
Leland Barton Avatar answered Oct 29 '25 01:10

Leland Barton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!