Whats wrong with my Mongo query? - mongodb

I've recently set a path in my vi .bash_profile to my mongo commands. I know this works because it was working yesterday.
However when I do it now I get this error:
AMAC02MX3APF8J3:~ james.flan$ mongo
MongoDB shell version: 3.0.3
connecting to: test
2015-05-19T11:34:58.708+0100 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2015-05-19T11:34:58.710+0100 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
Here is the content in my vi .bash_profile:
alias mongod="mongod --dbpath /Users/ryan.garrett/Documents/Software/MongoDB/data"
export PATH="/Users/ryan.garrett/Documents/Software/MongoDB/bin:$PATH"
Can someone please tell me how to connect to the server?

Check your /etc/hosts for localhost entry and also make sure that mongod is listening to all interfaces, you can check by netstat -an|grep mongo.

Related

Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27

I want to change the default port of mongodb so I did :
sudo nano /etc/mongod.conf
# network interfaces
net:
port: 27042
bindIp: 127.0.0.1
and
sudo service mongod start
But now when I want to run "mongo" I got this error:
MongoDB shell version v4.0.24
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2021-05-18T12:44:36.436+0200 E QUERY [js] 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 :: Connection refused :
connect#src/mongo/shell/mongo.js:356:17
#(connect):2:6
exception: connect failed
The message says " couldn't connect to server 127.0.0.1:27017" despite I changed the port in mongod.conf. I even tried to reboot my computer but it still not working.
UFW is not active si I don't think it's a firewall problem.
Based on your mongod.conf file, MongoDB will run on port 27042. When you run the command mongo without parameter --port, it will connect to the default port 27017 then you have the error.
I think this command mongo --port 27042 will work.

Connection error while installing mongodb on Fedora 28

I have been trying to install Mongodb but it keeps failing midway. When the download is complete, installation fails with a connection error:
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-08-17T12:26:33.340+0200 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-08-17T12:26:33.340+0200 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
What I've tried:
1. Changing the port:
mongo --port 4332
but it doesn't connect still:
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:4332/
2018-08-17T12:32:55.743+0200 W NETWORK [thread1] Failed to connect to 127.0.0.1:4332, in(checking socket for error after poll), reason: Connection refused
2018-08-17T12:32:55.743+0200 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:4332, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
Reinstalling the DB shows up as complete but I still can't start it. Check out the screenshot
Checking for any config files in /etc/mongo* or /var/lib/: there is none.
Note: There's no mongod service available too.
the installation seem to have worked, but the mongod was not started.
MongoDB need two element :
the "mongo" shell utility, who is used to connect to the database direcly
the "mongod" service, who is the true database programs.
to start the mongod, simply use a cmd and use the "mongod" command. this command may fail if :
the port is already used (default is 27017)
the dbpath directory was not created (default is /data/db)
Fedora repository do not install both at the same time.
the shell is in the repository under the "mongodb" name
the server is under the name "mongodb-server"
so to install both, you need to do
dnf install mongodb mongodb-server
and you can then start the mongod service with
sudo service mongod start
more information

Mongo failed to start

I am running a mean app, but when I go to run 'mongo', I get the following error:
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
2018-07-25T02:15:24.329-0500 E QUERY [js] 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 :: Connection refused :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
I am sure I am missing something simple here.
mongo is the Mongo shell. It connects to the Mongo daemon, mongod, which isn't running - hence the error.
At the command-line: sudo mongod
Enter your password, and the daemon should start. Now, when you run mongo it should start up ok.

How to connect to MongoDB

I am conecting mongo db everyday ,it worked fine but today it troubled me with the below error,can anyone help me please.
MongoDB shell version: 2.6.10
connecting to: test
2017-01-10T14:26:13.073+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-01-10T14:26:13.074+0530 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
Run the following command
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart

Could not connect to mongodb. errno:111 Connection refused

I am using mongodb on ubuntu-16.04 but mongodb give server connection error:
MongoDB shell version: 3.2.9 connecting to: test
2016-09-23T12:01:10.258+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-09-23T12:01:10.286+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : connect#src/mongo/shell/mongo.js:229:14 #(connect):1:6 exception: connect failed
What can I do?
looks like your mongod process is not running on port 27017. Make sure your mongod process is running maybe verify with linux command.
If you start mongod process and even then it's failing to connect with mongo command, it means it's failing to intialize, check out designated mongo log file for the reason