MongoDB - couldn't connect to server 127.0.0.1:27017, caused by :Connection refused : connect#src/mongo/shell/mongo.js:374:17 - mongodb

I installed mongodb with homebrew and i use Mac OS Big Sur
when I start mongo db with
$ brew services start mongodb-community
It says that mongodb it successfully started but when i run
$ brew services list
The status of mongodb-community is "error" and if I try to type the command "mongo" in the cmd it gave me the problem explained in the title of this question:
MongoDB shell version v4.4.3
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:374:17
#(connect):2:6
exception: connect failed
exiting with code 1

I ran the following in command line to fix the problem.
mongod --dbpath /usr/local/var/mongodb
this was directly after a re-install.
The error message that clued me in was:
{"t":{"$date":"2021-04-22T11:33:48.608-04:00"},"s":"E", "c":"STORAGE", "id":20557, "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}
more specifically
"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."

if you want to run mongodb type on terminal:
mongod --dbpath /usr/local/var/mongodb
If it not works use only:
mongod
And if you want to make CRUD in your db via SHELL or TERMINAL, run this :
mongo

-Archlinux
Search for [.mongodb / mongosh /]
Give execute permission to config.

Related

error starting mongodb with brew start on macOS Catalina 10.15.6

I have tried a few troubleshoots to no avail. They don't seem to match my specific error. I start mongodb with
> brew services start mongodb-community
The terminal says it is succesfully started, but when i
> brew services
to check mongodb's status it says error. No explanation.
But if I open up a new terminal and run mongo, I do however get a more detailed error.
> 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 :
I have found a solution to this problem. The socket exception error is apparently being thrown because the root owns the
/tmp/mongodb-27017.sock
solution
sudo rm -rf /tmp/mongodb-27017.sock
re start mongodb with
brew services start mongodb-community#4.4
it will create a new
/tmp/mongodb-27017.sock
which is owned by user. You can check by
ls -lsah /tmp/mongodb-27017.sock
my output was then
0 srwx------ 1 userName wheel 0B Apr 8 12:05 /tmp/mongodb-27017.sock
where username was previously root.
my solution was found here
https://stackoverflow.com/a/62196227/15311479

mongod and mongo both are not running, showing error, can anyone tell whats the problem

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
I had the same problem. Try starting the mongo shell with:
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log
Details are in the mongoDB docs:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x-tarball/

MongoDB is not running as service

I have installed Mongo on my OSX
$ brew info mongodb
mongodb: stable 4.0.2 (bottled)
...
I'm starting MongoDB service by this command:
$ brew services start mongodb
I can observe the status of mongodb:
$ brew services list
Name Status User Plist
mongodb started megas /Users/megas/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
...
But when I'm running mongo client it give me an error:
$ mongo
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
2018-09-19T15:18:22.490+0300 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:257:13
#(connect):1:6
exception: connect failed
When I manually start mongod then it works as it should be.
What I'm missing here?
Update:
If I run it manually it throughs message and stops
$ mongod --config /usr/local/etc/mongod.conf
2018-09-19T21:47:51.531+0300 I CONTROL [main] Automatically disabling
TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
$ cat /usr/local/etc/mongod.conf
# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb
# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true
# Only accept local connections
bind_ip = 127.0.0.1

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

Whats wrong with my Mongo query?

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.