Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb - Difference between running "mongo" and "mongod" databases

So, I'm sure I'm missing something simple here, but when I run mongo as a daemon (using mongod --fork or just mongod), I see different database content than if I just run "mongo" on the host machine.

My only assumption is that the data is being stored somewhere other than /data/db when it's running just the shell, and switches to /data/db when I boot the mongod. In that case, how do I get at my data when running mongod?

like image 634
Jesse Avatar asked Feb 03 '11 06:02

Jesse


People also ask

What is the difference between mongod and mongo?

Here, Mongod is the server component. You start it, it runs, that's it. By definition we also call it the primary daemon process for the MongoDB database which handles data requests, manages data access, and performs background management operations. Whereas Mongo is a default command line client.

What is mongod and mongo command?

MongoDB Mongo shell is an interactive JavaScript interface that allows you to interact with MongoDB instances through the command line. The shell can be used for: Data manipulation. Administrative operations such as maintenance of database instances.

What is the role of mongod process in MongoDB?

mongod is the primary daemon process for the MongoDB system. It handles data requests, manages data access, and performs background management operations.

What is mongod process?

The mongod process is the primary database process that runs on an individual server. mongos provides a coherent MongoDB interface equivalent to a mongod from the perspective of a client. The mongosh binary provides the administrative shell.


2 Answers

I think there is some confusion here.

mongod is the "Mongo Daemon" it's basically the host process for the database. When you start mongod you're basically saying "start the MongoDB process and run it in the background". mongod has several default parameters, such as storing data in /data/db and running on port 27017.

mongo is the command-line shell that connects to a specific instance of mongod. When you run mongo with no parameters it defaults to connecting to the localhost on port 27017. If you run mongo against an invalid machine:port combination then it will fail to connect (and tell you as much).

Ideally, when doing anything other than just "playing around", you'll use the Command Line Parameters for starting mongod. By the same measure you should start the mongo shell with explicit instructions.

Based on your description, I think you may be encountering an issue regarding the use of default databases. Try starting mongo with the following (where dbname is your database name)

./mongo localhost:27017/dbname 
like image 52
Gates VP Avatar answered Sep 29 '22 07:09

Gates VP


Yes, this might be a naive answer to this question but I am putting it forward so people can understand it easily!

Mongod:

mongod

(Short for Mongo Daemon) is a background process used by MongoDB server to get things done. This process is responsible for managing the whole MongoDB server tasks such as accepting requests, responding to users, managing memory requirement of MongoDB server operations and other things essential for MongoDB Server to run.

TLDR; Basically it is the MongoDB server

Mongo:

Mongo

on the other hand, is an interactive JavaScript shell interface to MongoDB, which provides a powerful interface for system administrators as well as a way for developers to test queries and operations directly with the database. mongo also provides a fully functional JavaScript environment for use with a MongoDB

TLDR; Basically I think it as mongodb client which can be used as a shell to get access to MongoDB database server run my mongod instances

like image 34
Mr. Suryaa Jha Avatar answered Sep 29 '22 07:09

Mr. Suryaa Jha