8

I just installed MongoDB version 3.2.4 on Ubuntu 15.10 and I want to run the mongo shell. All docs are suggesting to execute first the command cd <mongodb installation dir>

My question is where is that mongodb installation dir? How I can find it?

Apparently it may be something wrong with the mongod. Could not find /usr/bin/mongod Details below.

root@levilinode:/usr/bin# service mongod status
● mongod.service - LSB: An object/document-oriented database
   Loaded: loaded (/etc/init.d/mongod)
   Active: active (exited) since Tue 2016-04-12 14:22:45 EDT; 1h 37min ago
     Docs: man:systemd-sysv-generator(8)

Apr 12 14:22:45 levilinode systemd[1]: Starting LSB: An object/document-oriented database...
Apr 12 14:22:45 levilinode mongod[16541]: Could not find /usr/bin/mongod
Apr 12 14:22:45 levilinode systemd[1]: Started LSB: An object/document-oriented database.
Apr 12 14:24:02 levilinode systemd[1]: Started LSB: An object/document-oriented database.
Apr 12 14:24:26 levilinode systemd[1]: Started LSB: An object/document-oriented database.
Apr 12 15:56:15 levilinode systemd[1]: Started LSB: An object/document-oriented database.

However that files seems to be there:

root@levilinode:/usr/bin# ls -la mong*
-rwxr-xr-x 1 root root 19816422 Mar  7 18:32 mongo
-rwxr-xr-x 1 root root 35865168 Mar  7 18:32 mongod
-rwxr-xr-x 1 root root 14661359 Mar  7 18:32 mongodump
-rwxr-xr-x 1 root root 10523458 Mar  7 18:32 mongoexport
-rwxr-xr-x 1 root root 10395740 Mar  7 18:32 mongofiles
-rwxr-xr-x 1 root root 10636848 Mar  7 18:32 mongoimport
-rwxr-xr-x 1 root root 10125973 Mar  7 18:32 mongooplog
-rwxr-xr-x 1 root root 35551461 Mar  7 18:32 mongoperf
-rwxr-xr-x 1 root root 17331345 Mar  7 18:32 mongorestore
-rwxr-xr-x 1 root root 16086077 Mar  7 18:32 mongos
-rwxr-xr-x 1 root root 10353518 Mar  7 18:32 mongostat
-rwxr-xr-x 1 root root 10213613 Mar  7 18:32 mongotop
L.D
  • 1,279
  • 3
  • 15
  • 31
  • How did you install it? Using apt-get? – Joachim Isaksson Apr 12 '16 at 19:46
  • Yes, and apparently I can fetch the version, something like this: root@levilinode:~# mongo --version MongoDB shell version: 3.2.4 root@levilinode:~# mongod --version db version v3.2.4 – L.D Apr 12 '16 at 19:49
  • ...and if you just type `mongo` at the shell prompt? – Joachim Isaksson Apr 12 '16 at 19:49
  • I am just curious where the mongo binaries are? – L.D Apr 12 '16 at 19:49
  • Here it is: root@levilinode:~# mongo MongoDB shell version: 3.2.4 connecting to: test 2016-04-12T15:50:06.520-0400 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 2016-04-12T15:50:06.520-0400 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:224:14 @(connect):1:6 – L.D Apr 12 '16 at 19:50
  • Looks like I have a connectivity problem. – L.D Apr 12 '16 at 19:51
  • Looks like mongod isn't started. `sudo service mongod start` may fix it (although different apt packages for ubuntu may have slightly different naming) – Joachim Isaksson Apr 12 '16 at 19:54
  • Run the command and started the server, the status shows the server running. I think I am missing something in the networking config since I am getting this error message when I am starting the mongo shell: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused – L.D Apr 12 '16 at 19:59
  • try `netstat -na | grep 27017` maybe mongo is bound to any ip than localhost – DevLounge Apr 12 '16 at 20:12

3 Answers3

6

Multiple options:

  1. Using the system's files reference database:

$ sudo updatedb; locate mongo

  1. Restart your shell after install and try:

Both mongo and mongod commands are in the same dir, so if this dir has been added in your $PATH by the installer, this should tell you where they are.

$ which mongo
$ which mongod
  1. check manually in /var/lib or /usr/local or /usr/bin (must be a symlink though)
  2. check the daemon process line which usually give a hint about the path as it show the path of the config file

$ ps -efa | grep mongo

DevLounge
  • 8,313
  • 3
  • 31
  • 44
  • The $PATH is correct. root@levilinode:/usr/bin# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games – L.D Apr 12 '16 at 20:10
3

I think I solved the connectivity problem based on this question:

Then I run as indicated in the link shown above the commands:

sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart

An now all seems to be working ok.

Community
  • 1
  • 1
L.D
  • 1,279
  • 3
  • 15
  • 31
1

It would be in where you decompressed the tar.gz file that you downloaded from the MongoDB website. Inside, there is a mongod executable that you need to run before you can open the shell and operate the database.

Alternatively, you can create symlinks for the executables that you want to use:

sudo ln -s /dir/to/your/mongodb/folder/mongo /usr/local/bin/mongo
sudo ln -s /dir/to/your/mongodb/folder/mongod /usr/local/bin/mongod

And you can simply type in these two commands anywhere in terminal.

TPWang
  • 1,322
  • 4
  • 20
  • 39
  • OK, I found a lot of mongo* files in the folder /usr/bin The shell is working but is not connecting giving the error message: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused – L.D Apr 12 '16 at 19:58
  • what if he installed it from an official apt repo? This must be the case I think, otherwise it would be too simple. – DevLounge Apr 12 '16 at 19:58
  • @L.D this is because `mongod` is not running on your system yet. Follow the doc step by step. You must have to type: `mongod` or `sudo mongod` first – DevLounge Apr 12 '16 at 20:00
  • @L.D You need at least two terminal windows open to run mongodb, one running the "mongod" process, one running "mongo" shell. – TPWang Apr 12 '16 at 20:54