Could not connect to mongodb server - mongodb

I have mongodb server. When I try to connect to it with mongoclient from first machine I cannot connect to server but at the same time when I try to connect to mongodb server from second machine I can access database successfully.
I am getting following error from first machine
QUERY [thread1] Error: couldn't connect to server xxxxxxx:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:240:13
#(connect):1:6
exception: connect failed
I am having verson 3.6 of mongodb on all the server's.

Delete this file and then launch mongo service: /tmp/mongodb-27017.sock

Related

error mongo without mongod running first locally in win 10

I have this mongo.zip installed in my win 10.
I have set the environment path with bin.
Somehow whenever I start command line,
my mongo cannot start without mongod first.
C:\Users\asus>mongo
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: 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
but if I run mongod before mongo, mongo is running perfectly.
So, my question is: how do I running mongo without mongod locally.
PS. my compass is running and can connect to AWS cloud.
Please provide pictures if you can.
Thank you!
I think you, first of all, you have to know about the difference between them.
Mongod is the process of MongoDB.
Mongo is a shell. You can use it to connect and run any mongo command on any MongoDB.
So, your error means;
You are trying to connect your own MongoDB with typed mongo, because the default -host parameter is localhost. But your mongod process is not running. So you have to start it.
connecting to: mongodb://127.0.0.1:27017
127.0.0.1:27017 equals localhost.
If you have MongoDB (mongod process) on AWS. You should connect with below command
mongo --host mongodb0.example.com:28015

Could not run MongoDB server in Ubuntu system

I am trying to run MongoDB in my Ubuntu machine using the following command but I am getting some error.
Command:
mongo
Error:
connecting to: mongodb://127.0.0.1:27017<br>
2019-12-23T17:00:38.815+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused<br>
2019-12-23T17:00:38.818+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :<br>
connect#src/mongo/shell/mongo.js:251:13<br>
#(connect):1:6<br>
exception: connect failed
How can I resolve this issue and run MongoDB successfully?
Normally this is caused because you didn't start mongodb service before you try starting mongo shell. You can check for a system service status. If it is failing because of some error try to fix it and start the process. Below are few things that might help with it.
Check if mongodb service is up and running
sudo systemctl status mongodb
If not start mongodb service on your ubuntu machine
sudo systemctl start mongodb
Start mongo shell
mongo

mongo - couldn't connect to 127.0.0.1 - ip changed

I installed mongoDB and changed the IP to 10.3.Y.XX.
When i want to start mongo from terminal (> mongo), this error occurs:
Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1),
connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
Any idea how to solve this?
If you want to connect to something other than the default host (which is "localhost"), you need to tell your Mongo client application about it.
For example, on the command line you can do
mongo --host 10.3.x.y db_name

Amazon EC2 unable to connect to MongoDB via client mongo shell

I am unable to connect to remote MongoDB from my local Machine. Getting the below exceptions while trying to connect using Mongo shell.
Request from shell:
mongo --username[username] --password[password]--host [Public DNS] --port 27017
Response:
Failed to connect to :27017, reason: errno:61 Connection refused
2015-12-03T16:31:51.514-0500 E QUERY Error: couldn't connect to server , connection attempt failed
at connect (src/mongo/shell/mongo.js:181:14)
at (connect):1:6 at src/mongo/shell/mongo.js:181
I have followed the below template to configure the server on the Amazon cloud.
https://s3.amazonaws.com/quickstart-reference/mongodb/latest/doc/MongoDB_on_the_AWS_Cloud.pdf
Can anyone help me to resolve this issue.
Thank you in advance.

set up Apache2 virtual hosts and now MongoDB connection refused

I'm running Ubuntu 14.04 on an AWS EC2 instance with Apache2. This morning I upgraded my Apache2 settings to allow multiple virtual servers following these instructions: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
Just now I tried to access my MongoDB instance, but I cannot do it either through the PHP MongoDB driver or through the shell. I get this error when attempting to connect with a PHP MongoClient():
Failed to connect to: localhost:27017: Connection refused'
and I get this error when trying to run the mongo shell:
2015-06-03T19:23:57.307+0000 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-06-03T19:23:57.308+0000 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
Everything was running fine just last night, and I haven't directly modified MongoDB settings. What can I do to fix this? How do Apache2 settings relate to MongoDB? I've been trying to look through the MongoDB docs, but I don't see anything that looks relevant.
You need to setup Security Group for your EC2 instance. And allow Inbound connection for the mongodb port, in your case 27017.
When I went through the logs, I saw a message that there was insufficient room for "journal file." I rebooted my AMI on an EC2 instance with more storage and reinstalled Mongo. That did the trick. I had uploaded a few files to the instance after updating my Apache2 settings, so those few more files must have pushed the instance past what Mongo could tolerate. Too bad the error message wasn't more helpful, but I should have checked the logs sooner. It would also be nice if the logs had a more explicit message.