While trying to take mongodump, I am getting the below error
mongodump --host 127.0.0.1 --port 27017 --db csgdb
2018-12-12T05:16:39.928+0000 Failed: error connecting to db server:
no reachable servers
Even not able to login to mongo shell
mongo --port 27017
MongoDB shell version v3.4.7
connecting to: mongodb://127.0.0.1:27018/
2018-12-12T05:14:54.161+0000 E QUERY [thread1] Error: network error
while attempting to run command 'isMaster' on host '127.0.0.1:27018' :
connect#src/mongo/shell/mongo.js:237:13
#(connect):1:6
exception: connect failed
Any help?
Related
When I run the below command in CMD under Mongodb bin folder, it prompts an error message.
Can someone help me on this?
mongo --host 127.0.0.1 --port 27018
Here is the error prompt:
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27018/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27018, connection attempt failed:
SocketException: Error connecting to 127.0.0.1:27018 :: caused by :: No connection
could be made because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
Mongodb bydefault runs on localhost using port 27017, you do not need to explicitly mention that just use mongod command and it will start your mongodb server. If you want to run on specific port then mongod --port 27018 should work
mongo is just the CLI interface.
Use:
mongod --port 27019
Look here for more detail: https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/#specify-a-tcp-port
Ive installed Docker locally (mac) and tried to run a docker container using the following command.
docker run -it -p 27017:27017 mongoImageId
But when I tried to login in to the container via the mongo terminal client, Im getting the following error.
mongo --port 27017 -u "userName" -p "password" --authenticationDatabase "sampleDBName"
MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017/
2018-07-23T13:41:53.423+0530 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017' :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
But if I try to build the same image in an aws ec2 instance, it connects without a hazel. Does any one else also encountered the same issue and was able to find the root cause ?
Ref.
[1] - https://github.com/aashreys/docker-mongo-auth
I'd like to connect to my AWS instance and connect to my MongoDB database over localhost. The SSH tunnel seems to work, but when I try to connect with mongo I get a connection failed error.
SSH tunnel command:
ssh -i <path to key> -N -L 27017:++++++++++.us-west-2.compute.amazonaws.com:27017 ++++++#++++++++++.us-west-2.compute.amazonaws.com
Mongo client:
mongo -u +++++++ -p ++++++++++ mongodb://localhost:27017/+++++
MongoDB shell version v3.4.7
connecting to: mongodb://localhost:27017/++++++
2018-01-22T15:32:07.125+0100 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host 'localhost:27017' :
connect#src/mongo/shell/mongo.js:237:13
#(connect):1:6
exception: connect failed
On the tunnel side I then get:
channel 2: open failed: connect failed: Connection refused
I have tried the mongo command directly on the server then there it works fine.
On my Robo T3 client there is an option to connect over SSH and there the connection works just fine.
Any suggestions are greatly appreciated.
EDIT
When I start the mongo client, no new lines are added to mongdb log file. This indicates that the tunnel is not doing it's job...
According to this documentation, this error happens when you try to connect to a MongoDB server without ssl.
The solution then would be to connect using SSL, which can be done by adding --ssl to your connection query (so that it looks like this: mongo --ssl -u +++++++ -p ++++++++++ mongodb://localhost:27017/+++++).
Let me know if this works for you!
I have a database in www.myweb.io, which has SSL. The version of mongo is 2.6.12 in the server: the version of mongo in local is 3.4.1. I want to dump it into my local machine, modify it, and then restore back.
I tried
mongodump --host www.myweb.io --port 22 --username myname --password "mypassword"
and it gave me an error:
2017-11-20T20:57:07.775+0100 Failed: error connecting to db server: no reachable servers
Does anyone know what host and post I should set?
PS: in my localhost, I can use the following setting in Robo 3T to connect to the database:
1) under Connection, specify localhost:27017
2) under SSH, check Use SSH tunnel, specify xxx.xx.xx.xx:22 as SSH Address
In /etc/nginx/sites-enabled/myweb.io, there is listen 443 ssl.
you are not connecting via SSL or TLS to the database.
Use an ssh tunnel to establish a connection to your mongodb
ssh -N -L 27018:localhost:27017 user#www.myweb.io
you can specify -f to let ssh go in the background
Verify that the tunnel is working
Using mongodb
mongo --port 27018
Or telnet
telnet localhost 27018
dumping the database
mongodump --host 127.0.0.1 --port 27018 --db <dbName>
restore it somewhere, do your modifications
dump your local modifications
reapply the local modifications remote for example with mongorestore or mongoimport
I have this command to start MongoDB in a container:
docker run -p 27017:27017 --name cdt-mongo mongo
this is from these docs:
https://hub.docker.com/_/mongo/
I actually think the
-p 27017:27017
is superfluous. anyway.
Locally, I run the container in one terminal, and then in another terminal I issue the mongo command, and I get:
$ mongo
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
2017-05-02T11:27:22.864-0700 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-05-02T11:27:22.866-0700 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:237:13
#(connect):1:6
exception: connect failed
anybody know why I cannot connect to mongodb running in the container?
because I am on MacOS, I should not connect to
localhost:27017
but instead use the host/ip address of the docker-machine VM
HOST=$(docker-machine ip)
and then connect to it like so:
mongo --host $HOST