Cannot connect to mongod running in Ubuntu machine - mongodb

I would like to connect with mongo from a cmd shell in windows to a mongod database running in a Ubuntu virtual machine.
mongo is running fine in the Ubuntu terminal and from a putty shell
When I use mongo from a windows cmd shell, I got this error:
mongo.exe --host 192.168.1.6 --port 27017
MongoDB shell version: 2.4.6
connecting to: 192.168.1.6:27017/test
Sat Feb 01 14:45:32.181 Error: couldn't connect to server 192.168.1.6:27017 at src/mongo/shell/mongo.js:147
exception: connect failed
What should I do to be able to connect?
My goal is to use MongoVue to connect to the mongod database in the Ubuntu machine (by the way, MongoVue is not connecting even using its SSH options).
I am trying to connect to the mongod instance of a meteorjs application.
The meteor application is up and running and I can connect to the mongod instance running on the Ubuntu machine at port 3002, both in the Ubuntu terminal and with a putty shell.
stefano#MeteorDeploy:~$ mongo --port 3002
MongoDB shell version: 2.0.4
connecting to: 127.0.0.1:3002/test
PRIMARY> show dbs
local 0.0625GB
meteor 0.0625GB
I would like to connect to the mongod instance using MongoVue as alternative of the putty shell.
I did as in the docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/ but without success.

Meteor runs it's own instance of mongo per app. As you note since your edit, when you ssh into your VM you use --port 3002 to connect.
Now you could add that port to your mongo shell launch except for one problem
ps -ef | grep mongo
on your VM will show you the running instance of mongo along with it's startup options. By default this will be bound to 127.0.0.1 which is the loopback adaptor and not accessible outside of the VM.
So what you need to do is either change the startup options in your project, or use another instance on mongo installed on the local machine.
export MONGO_URL=mongodb://localhost:27017/your_db

By default mongod insllation on Ubuntu only listen to localhost, so you can't connect from Windows.
Edit /etc/mongodb.conf and change the bind_ip line (add your windows IP adress on the local network) so it will accept connection.
Be aware that by default mongod does not require authentification so you would maybe want to settup one.
Doc is here :
http://docs.mongodb.org/manual/reference/configuration-options/#bind_ip

For quick and dirty solution (not for Production):
Edit /etc/mongodb.conf and change the bind_ip to 0.0.0.0

Related

How can I install two versions of mongodb parallely in Ubuntu 12.04 ?

I have mongod 3.0.4 installed. I followed the steps from here. I also want to install mongo 2.6.10 as one of my project uses it. How can I have two versions installed so that I can use either one ?
You can run multiple mongoDB version on the same host as long as these version are not in the same Replica Set as a general rule (which judging by your question will not be a problem).
Deploy 2 installation paths.
Start the application using:
mongod --port 12345
(where 12345 is the port you specified)
To start the exe on a different port.
Default port is 27017 if port not specified in the command.
See http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
Example:
Deploy:
C:\mongo1\bin\mongod.exe
C:\mongo1\data\
C:\mongo2\bin\mongod.exe
C:\mongo2\data\
Execute:
start /b c:\mongo1\bin\mongod --dbpath "c:\mongo1\data" --port 27017
start /b c:\mongo2\bin\mongod --dbpath "c:\mongo2\data" --port 27050
When connecting using MONGO.exe be sure to specify port to connect to correct instance.

Mongo Shell couldn't connect to the local server

I'm starting MongoDB using the following command:
sumeet#sumeet-acer:~$ sudo service mongod start
I get a reply as:
mongod start/running, process 7209
sumeet#sumeet-acer:~$
But when I try to enter MongoDB shell by typing mongo I get the following error:
sumeet#sumeet-acer:~$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Fri Jun 12 14:01:59 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
By default, mongod and mongos use the 27017 port. Without any option, the client will try to connect to a server running on localhost and listening at that port.
A few general advices here:
check if the mongod server is really running (ps -edf | grep mongod);
check if it uses the default port (look in the config file1, or use nmap localhost -p0-65535 or netstat | grep 27017);
if mongod is not running, check in the log2 for clues about what goes wrong.
1 /etc/mongodb.conf (on Debian-like systems at least)
2 /var/log/mongodb (on Debian-like systems at least)
The default IP and Port for MongoDB is 127.0.0.1 & 27017.
If you are using config file for specifying settings than re-verify IP & Port mentioned in it.
If you are going with default option than mongod should function as expected.
try mongo 127.0.0.1:27017
this worked for me
For MongoDB 2.2.2 running on Ubuntu 12.10, it's in /var/lib/mongodb/mongod.lock
and after that running the repair command
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/
courtesy: https://stackoverflow.com/a/13700262/4907105

Connecting to Meteor Mongo from GUI

How do I connect to my Meteor Mongo instance from a GUI, e.g. MongoChef (I am on Windows running an Ubuntu Virtual Machine which has the Meteor application on it)?
I have tried connecting using the IP address of my running Virtual Box, with both port 3001 and 27017 with no joy - should I be setting up some port forwarding or something?
This applies to an out-of-the-box install of Mongo when Meteor is installed:
The mongo daemon mongod binds to 127.0.0.1 so you need to connect to it via a SSH tunnel if your client supports it. MongoVUE and Mongo Chef both allow this type of connection. Once you SSH into the VM, you can connect to 127.0.0.1:3001 without any trouble. It does not require a password or username, just the database to be set as meteor.

Cannot access to my datsbase when running the server as a service

I have recently installed Mongodb on my ubuntu machine according to the linux manual in mongodb website. everything looks ok when i run the command "mongod" to start a mongodb server.when I try to run
sudo service mongod start
it says that mongod start/running, proccess 3369
but when I try to access the database from the Mongodb GUI it cannot acces it. nor from the chrome itself using the port 27017.
how can i fix this?

How to identify the port of minimongo running inside meteor?

I am novice in meteor. I was developing an application which leverages the mongo db which comes with the meteor package. The meteor is running under the port 3000, but i want to know under what port the mini mongo runs. I am using a tool MongoVUE to view all the collections that is under mongo running in a port. I was able to view the mongo collections when i run the standalone mongo since i know the port for that but for this mini mongo running under meteor i am not able to know the port. Any help is appreciated.
Mingomongo runs in the browser, it's a client-side Javascript library.. it runs in memory, it doesn't have a port.. it enables you to query data published by the server in your client application, using MongoAPI style syntax..
to get the connection string of the Mongo instance running on the server (say, if you want to connect from a different client, or just see the port number) run
meteor mongo -U
Using ps auxww|grep mongo|grep meteor on my Fedora system I get:
jwulf 20635 0.3 2.6 150800 41336 pts/1 Sl+ 17:07 0:01 /usr/lib/meteor/mongodb/bin/mongod --bind_ip 127.0.0.1 --smallfiles --port 3002 --dbpath /home/jwulf/tools/leaderboard/.meteor/local/db
So it is running on port 3002 on my system. Starting mongo with --port 3002 allows me to connect to the Meteor mongo server and copy data into the database.
You can also connect to the local instance by running meteor mongo in your Meteor app directory.
The database itself is at <app-name>/.meteor/local/db on my Fedora system.
In meteor 0.8.3 it's using port 3001
so I run:
mongo localhost:3001
use use meteor
and I'm good to go...thanks to Sitapati Das for the command above...