Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "mongo" and "mongod"?

Tags:

mongodb

I've installed MongoDB and I've found some unlogical things and I hope someone will answer me:

  1. When I execute "mongo" I get logged into shell
  2. When I execute "mongodb" I get the following errors:

     2016-06-23T22:58:39.302+0000 I CONTROL  [initandlisten] MongoDB starting : pid=7221 port=27017 dbpath=/data/db 64-bit host=debian
     2016-06-23T22:58:39.302+0000 I CONTROL  [initandlisten] db version v3.2.7
     2016-06-23T22:58:39.302+0000 I CONTROL  [initandlisten] git version: 
     4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
     2016-06-23T22:58:39.302+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1t  3 May 2016
     2016-06-23T22:58:39.302+0000 I CONTROL  [initandlisten] allocator: tcmalloc
     2016-06-23T22:58:39.302+0000 I CONTROL  [initandlisten] modules: none
     2016-06-23T22:58:39.302+0000 I CONTROL  [initandlisten] build environment:
     2016-06-23T22:58:39.302+0000 I CONTROL  [initandlisten]     distmod: debian71
     2016-06-23T22:58:39.303+0000 I CONTROL  [initandlisten]     distarch: x86_64
     2016-06-23T22:58:39.303+0000 I CONTROL  [initandlisten]     target_arch: x86_64
     2016-06-23T22:58:39.303+0000 I CONTROL  [initandlisten] options: {}
     2016-06-23T22:58:39.325+0000 E NETWORK  [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
     2016-06-23T22:58:39.325+0000 E NETWORK  [initandlisten]   addr already in use
     2016-06-23T22:58:39.325+0000 E STORAGE  [initandlisten] Failed to set up sockets during startup.
     2016-06-23T22:58:39.325+0000 I CONTROL  [initandlisten] dbexit:  rc: 48
    

What is the difference between two terminal commands: mongo as a first, and mongodb as a second?

MongoDB is great because my project is schema-less but it's always a horrible experience to configure it, create roles, authorization etc.

Thanks.

like image 551
Nedim Avatar asked Jun 23 '16 23:06

Nedim


2 Answers

  • mongod is the server, to which requests to connect database are passed for example.
  • In above error, it shows that port address 27017 is in use. It means your mongod is already runnning. You just need to run command 'mongo' to access the Mongodb shell.
  • There is another possibility that some other process is running on port 27017
  • netstat -n | grep 27017 to check if process is running and kill -9 $(lsof -ti:27017)'
like image 112
Tushar Avatar answered Oct 10 '22 14:10

Tushar


To use any database service, you have to start the database Server and same is the case with mongodb, the command mongod is used to start the MongoDB Server on your local machine or server.

In your question you have asked for the command mongodb that's not correct you need to run command mongod, 'b' is not the part of this command.

  • When you run the mongod, it starts your mongodb server on default port 27017.
  • Then you open another terminal and use the command mongo to enter into the mongo shell and perform your database operations.

The difference between the both commands is that mongod starts the mongodb server and mongo allows you to enter into mongo shell to perform further database operations.

Also, when you install mongodb, you have an option to install it as a service. Installing mongodb as a service starts the mongodb server in background when you boot your system.

like image 25
Anidhya Bhatnagar Avatar answered Oct 10 '22 15:10

Anidhya Bhatnagar