Cannot connect with Mongo - node.js

When I try to launch the mongo shell running the 'mongo' command in the terminal I get this error:
connecting to: mongodb://127.0.0.1:27017
2017-12-23T17:52:51.318+0100 W NETWORK [thread1] Failed to connect to
127.0.0.1:27017, in(checking socket for error after poll), reason:
Connection refused
2017-12-23T17:52:51.319+0100 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
I cannot figur out what is the problem...

First, you need to check whether mongo server is running on your local system by visiting below url in the browser.
http://127.0.0.1:27017
you can run the below command in case of ubuntu.
$ sudo service mongod start
Then, Run:
$ mongo

Related

Mongodb error: couldn't connect to server 127.0.0.1:27017 connection refused

I downloaded mongodb-bin and mongodb-tools-bin in AUR.I just typed sudo systemctl enable mongodb and just ran mongo.This is the error i got:
$ mongo
MongoDB shell version v5.0.5
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 :: Connection refused :
connect#src/mongo/shell/mongo.js:372:17
#(connect):2:6
exception: connect failed
exiting with code 1
I saw somebody say to just delete /var/lib/mongodb/mongod.lock but when i checked there was no mongod.lock file
I have fixed the problem by deleting /tmp/mongodb-27017.sock.I have found the answer here

Failed to connect to mlab Database

I'm trying to connect to my database on mlab through mongodb.
I have cd to mongodb directory, then I run the code and all I get is this error. If I try to connect over localhost it's fine but on real server I get the error below:
./bin/mongo ds151508.mlab.com:51508/dansql -u xx -p xxx
MongoDB shell version v3.6.3
connecting to: mongodb://ds151508.mlab.com:51508/dansql
2018-02-28T09:31:17.748-0700 W NETWORK [thread1] Failed to connect to 34.228.213.238:51508, in(checking socket for error after poll), reason: Connection refused
2018-02-28T09:31:17.749-0700 E QUERY [thread1] Error: couldn't connect to server ds151508.mlab.com:51508, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed

MongoError: js:237:13 connect failed [localhost:27017]

I would like to install Mongodb on IntelliJ (already with Angular and Node.js). I installed MongoDB and changed my environment variables. I use Windows 10. When I try the command line : "mongo dbs show", I get this error :
MongoDB shell version v3.4.10 connecting to:
mongodb://127.0.0.1:27017/dbs 2017-11-20T16:59:43.003+0100 W NETWORK
[thread1] Failed to connect to 127.0.0.1:27017 after 5000ms
milliseconds, giving up. 2017-11-20T16:59:43.003+0100 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
In order to fix it, I tried the instructions of related posts, that is to say :
-Create a data directory in "MongoDB\Server\3.4\data"
-Change the directoy "mongod --dbpath=..."
-Change the allowed port to 27017 thank to "add --port 27017"
I did those operations but it doesn't solve the problem. Would you know how to fix it ? I thank you very much in advance !

MongoDB connect failed

My problem here is that even after setting up mongod.exe "mongod.exe --install --logpath c:\mongodb\logs --logappend --dbpath c:\mongodb\data\db --directoryperdb", when i start up mongo.exe on another shell, i get a connection error
MongoDB shell version: 3.2.9
connecting to: test 2016-10-01T17:20:11.543+0300 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017 after 5000 milliseconds, giving up.
2016-10-01T17:20:11.543+0300 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 is it that i'm not doing right? Running it on Windows 10. Mongod.exe after set up waits for a connection.
it is may be because of the OS privileges so for example if you are in
windows try to open the cmd(command line) in administrator mode and
try to start the MongoDB server again,i hope this fix your problem
This is because the db server must be running and waiting for connections. I think you should start your db server first with ./mongod in the root directory and leave it running. Hopefully this will help!

connection to mongo db failed

failed to to connect to mongo. Very new to this need help please.
this is what i get:
MongoDB shell version: 3.2.9
connecting to: test
2016-09-12T00:09:34.516+0100 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
2016-09-12T00:09:34.517+0100 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

Resources