mongodb Network is unreachable on mac - mongodb

Sorry I have ask the same question again from Robo 3T Error : Network is unreachable
Beacause I really can't find out the file /etc/mongod.conf.
My machine is mac and use homebrew install mongodb.
There is no mongod.conf in my path /usr/local/var/mongodb.
Any help would be appreciated.
According suggestion the path /usr/local/opt/mongodb/mongod.conf
My /usr/local/opt like this:
Try brew uninstall mongo and brew install mongo.
Connect it still get the same error.
But find the file mongod.conf in the path /usr/local/etc.
I try to remove the file and restart mongodb server then type command mongo get the error:
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
2018-09-18T14:38:21.241+0800 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
It is so strange...:(

You can create the mongod.conf at any folder on your Mac you like and pass the path to this file during the start of the Mongo DB server like:
mongod -f /path/to/mongod.conf
You have to create the mongod.conf manually e.g. on the desktop of your Mac. You can do this with the following commands.
Open a terminal
$ cd Desktop
$ touch mongod.conf
Then open the created (currently empty file) with a text editor of your choice and fill in your configurations (Here you can find a manual for the config file: https://docs.mongodb.com/manual/reference/configuration-options/)
Then start your Mongo DB server with
$ mongod -f /Users/YOUR_USERNAME/Desktop/mongod.conf
Please replace YOUR_USERNAME with your MacOs username you are currently working with

Related

Having trouble installing/uninstalling MONGODB

I am trying to install MONGODB, followed a bunch of tutorials and haven't had luck. Prior to this, when I typed mongo in the terminal, it would say it wasn't found. However I stumbled upon https://www.mongodb.com/community/forums/t/unable-to-connect-to-mongo-shell-error-connecting-to-127-0-0-1-27017-caused-by-connection-refused-connect-src-mongo-shell-mongo-js13/89945/2 and copied
>mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/100YWeatherSmall?replicaSet=Cluster0-shard-0" --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics
into my terminal. I want to restart fresh and get rid of everything related to mongo. However, even after following the instructions from https://www.mongodb.com/basics/uninstall-mongodb for mac, I can't seem to restart fresh. I seem to get
MongoDB shell version v5.0.9
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
My problem is that I am having trouble installing MongoDB and ended up blindly copying something. Now I can't seem to go back to the original message where after I type mongo, it would give the message saying it wasn't found. Instead, I get the message that I mentioned above. Any ideas on how to fix this? Thanks!
You may want to try these commands to repair and restart your mongodb server:
1) Remove .lock file
sudo rm /var/lib/mongodb/mongod.lock
2) repair the mongodb
mongod -–repair
3) start the mongod server
sudo service mongod start
4) start the mongo client
mongo

Not able to connect to mongodb database

Every time if my server restarts by mistake or I stopped and then restart I'm not be able to connect to my mongodb. I get this below error and according to this 27017 port is not open but in my security group I opened this port.
MongoDB shell version v5.0.2
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```
So, I don't know what I'm doing wrong please help me because I'm facing this issue from very long time and to rid of this I've to always setup new mongodb
You need to define the MongoDB as service and set to automatic start.
On Windows add lines similar to
processManagement:
windowsService:
serviceName: mongod
displayName: MongoDB
description: MongoDB Server
to your configuration file (typically mongod.conf or mongod.cfg), if not already existing.
Then the easiest way to install the service is running
mongod.exe --config <your config file> --install
On Linux (Redhat, Centos, etc.) it works like this.
Copy default service file
/usr/lib/systemd/system/mongod.service to /etc/systemd/system/mongod.service
Customize service file /etc/systemd/system/mongod.service, if needed
Enable the service: systemctl enable mongod
Start the service: systemctl start mongod

Running `mongo` in the command line is giving error

I am trying to start a MERN app, I have installed mongo and any relevant things. But when I run mongo in my terminal the following appears.
I have looked across the board but the solutions do not help me. I am also running on Ubuntu 20.04.
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
Fixed the issue by running
$ sudo rm -rf /tmp/mongodb-27017.sock
$ sudo service mongod start
Try to start the MongoDB server first running mongod command or from task manager>services> MongoDB server> right-click and start it
Read this Document for more

MongoDB, NodeJs. No connection could be made because the target machine actively refused it. :

I am trying to connect to my MongoDB database in localhost. While I type mongo in command shell I am getting an error in the command shell:
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 :: No connection could be made because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:341:17
This will start the mongo server as a service:
brew services start mongodb-community
command mongod will run the MongoDB server using the default configuration. You can change these configurations by locating the default path of the configuration files.
The primary daemon process for the MongoDB database system is called mongod. You need to start this service before making connection attempts.
You can do this in Ubuntu by:
sudo service mongod start
or,
sudo systemctl start mongod
Start mongod on system boot by:
systemctl enable mongodb.service
I had the same issue.
When running mongod command, it mentioned the C:/data/db as E:/data/db path.
After I created the folder in mentioned E:/data/db path it works!
For windows user
1. Type ctrl + r
2. Scroll to mongodb server
3. start the server
do you have a linux distro? If you do, the solution is a bit annoying as you have to do it everytime you start your pc. The solution is:
Type "mongo" and "mongod" once in the terminal. It will show an error, don't worry, that's the whole point
type this:
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
sudo service mongod restart
tip: copy the whole thing and paste on the terminal using ctrl+shift+v. You're welcome :-)

"mongo" command fails to connect

I am trying to install MangoDB. I have already installed the log and configure files. When I run mongo command in mongodb/bin directory, I receive the error messages:
mongo MongoDB shell version: 3.0.4, connecting to: test
W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1)
This is my mongod.cfg configure file; I don't know if it is correct.
logpath=C:\mongodb\log\mongo.log
dbpath=C:\mongodb\data
rest=true
Can anyone help? Thanks.
There are many more hurdles you can face during installation of mongodb. Installation of Mongodb is not as easy task I am also stuck with these issue for some time.the only option is to install mongodb step by step as described on Mongodb's official website.
Dont miss any step!.
here is the link http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/