Unable to connect specific mongo instance port - mongodb

Today morning i'm able to create 2 different mongo instances on port 27010 and 37010 and i'm able to replicate using mongo-connector. But now after system restart i'm not able to connect to port 37010 using below command.
C:\Program Files\MongoDB 2.6 Standard\bin>mongo --port 37010
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:37010/test
2016-09-12T18:08:14.733-0500 warning: Failed to connect to 127.0.0.1:37010, reason: errno:10061 No connection could be made because the target machine actively refused it.
2016-09-12T18:08:14.756-0500 Error: couldn't connect to server 127.0.0.1:37010 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed
It is working fine if i just give mongo where it is connecting only to default port of 27010. Morning also i faced same problem where i deleted all my mongo windows service and running without mongo windows service. But again i'm facing same problem. Kindly advise.
Below is my config files.
mongo.config.txt
##store data here
dbpath=C:\Program Files\MongoDB 2.6 Standard\data
##all output go here
logpath=C:\Program Files\MongoDB 2.6 Standard\log\mongo.log
logappend=true
#port number
port=27017
##log read and write operations
diaglog=3
#replica set name
replSet=rs1
# only run on localhost for development
bind_ip = 127.0.0.1
mongo2.config.txt
##store data here
dbpath=C:\Program Files\MongoDB 2.6 Standard\data2
##all output go here
logpath=C:\Program Files\MongoDB 2.6 Standard\log2\mongo.log
logappend=true
#port number
port=37017
##log read and write operations
diaglog=3
#replica set name
replSet=rs2
# only run on localhost for development
bind_ip = 127.0.0.1

I got answer to my problem by following the steps mentioned in below blog.
http://zdk.github.io/create-a-three-member-mongodb-replica-set
Somehow it didn't work for me with configuration file. But I resolved my problem by executing commands in command line .

Related

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

mongodb Network is unreachable on mac

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

MongoDB Sharding - Unable to reach primary for set c1

I have a huge amount of data, therefore I am going to use sharding on MongoDB. I have exactly followed the same steps mentioned here, but getting the warning Unable to reach primary for set c1 when I execute the command mongos --configdb c1/mongodb-test-config on the front-end machine.
Also, when I execute the next command mentioned in the linked tutorial mongo localhost:27017 on the front-end machine, getting the error couldn't connect to server localhost:27017.
Notes in advance:
I have already configured iptables to allow connections on the port 27017
I have set bindIp to 0.0.0.0 in the mongod.conf file
MongoDB Version: 4.0.2
Ubuntu Version: 16.04.5
All the machines (2 shards, 1 config server, and 1 front-end) are located in the same network, and successfully connect with each other.

Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017'

.> mongo
MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
2018-06-26T17:37:13.313+0530 I NETWORK [thread1] Socket recv() An established connection was aborted by the software in your host machine. 127.0.0.1:27017
2018-06-26T17:37:13.313+0530 I NETWORK [thread1] SocketException: remote: (NONE):0 error: SocketException socket exception [RECV_ERROR] server [127.0.0.1:27017]
2018-06-26T17:37:13.313+0530 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017' :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
This problem can happen when trying to connect to a database which requires SSL.
This error is usually caused by attempting to connect without SSL to a MongoDB server that requires it. Use the following command to connect:
mongo --ssl --username "$USERNAME" --password "$PASSWORD" --host "$HOST" --port "$PORT"
See Mongod logs to find the root cause. For me it was leaking connections from one of the clients, this is what I found in logs:
NETWORK [listener] connection refused because too many open connections:
(SSL causing the issue)
You can connect with it using this command :
mongo --host 127.0.0.1:27017 --tls --username fake --password fakepassword --authenticationDatabase admin --sslAllowInvalidHostnames
Disables the validation of the hostnames in TLS/SSL certificates.
Allows mongo to connect to MongoDB instances even if the hostname in
their certificates do not match the specified hostname.
Deprecated since version 4.2: Use --tlsAllowInvalidHostnames instead.
WARNING :
Although available, avoid using the --sslAllowInvalidCertificates
option if possible. If the use of --sslAllowInvalidCertificates is
necessary, only use the option on systems where intrusion is not
possible.
If mongosh (and other MongoDB Tools) runs with the
--sslAllowInvalidCertificates option, mongosh (and other MongoDB Tools) will not attempt to validate the server certificates. This
creates a vulnerability to expired mongod and mongos certificates as
well as to foreign processes posing as valid mongod or mongos
instances. If you only need to disable the validation of the hostname
in the TLS/SSL certificates, see --sslAllowInvalidHostnames.
See MongoDB official Doc
just go simply on task manager and click on service
see given image below to copy the link on the URL
find MongoDB and click on open Service.
see given image below to copy the link on the url
then again find MongoDB and start stopped DB to running mode just click on green point button and you MongoDB is again started connecting.
[see given image below to copy the link on the url]
In my case , I was running several applications on other ports. The above solutions did not worked well for me .
Finally I closed all the tabs of code editor and web-app , and restarted it . Now it works fine .
Well! You can just restart the system, that will also work with least hassle.
As stated, this can happen because the server requires TLS in the connection. You will see the reason in server logs.
For someone who ends here without knowing how to fix it (like me) it's worth noting how to connect to those servers:
In command line you can use the --tls option (https://docs.mongodb.com/manual/tutorial/configure-ssl-clients/)
mongo --tls [other params and/or connection string]
If using a connection string alone, you can add tls=true param:
mongo://[user]:[pass]#[host]/[db]?tls=true[&others]
I was getting error in the mongod logs that read
WiredTiger metadata corruption detected
To fix the error I did the following:
As per suggestion here I ran command mongod --dbpath /data/db --repair.
The logs from command above complained that my version of mongod was too recent (I was on 4.2.x) and I had to try on mongod 4.2 or earlier.
Downgraded to mongod 4.2
Ran command mongod --dbpath /data/db --repair again, and this fixed issue.
I do run mongod inside Docker, so I had to take an extra step to find out path of the mongo DB file, docker inspect <id of mongod container>, and grab the path from the HostConfig.Binds[0] property of the resulting JSON, and stick that in the --dbpath option of the repair command mongod --dbpath /data/db --repair
In my case it is net.maxIncomingConnections: 10 in the config file and MongoDB Compass.
All available connection slots the server has, are consumed by other clients and that causes new connection requests to just drop.
I was not aware that Compass would open so many connections. When I closed it, my problem was solved.
The default connection limit is 65536 as stated in config options
I don't know why this happens but sometimes my mongo instance fails to start properly. Just shutting it down and restarting it worked for me.

Mongo DB is started, but it doesn't work

I have 2 servers: One Ubuntu Server and a debian Server. I've installed Mongo DB and mongod will start, but when I try the command "mongo", I get the follow message:
MongoDB shell version: 2.4.9
connecting to: test
Tue Jun 28 19:01:21.922 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
I start the MongoDB with this command:
clouduser#caridio-ubuntu-2:~$ sudo service mongodb start
sudo: unable to resolve host caridio-ubuntu-2
mongodb start/running, process 18555
I tried to set an other dbpath and to install an older version of MongoDB. I set up differnt servers. MQTT and Tomcat works both.
Here my config:
it's an answer from 2 years ago
bindIP = [127.0.0.1,141.28.102.148]
so try to add your ips inside the [ ]
if you don't have others interface you can use bindIP = 0.0.0.0
source https://stackoverflow.com/a/34698336/6523542
maybe duplicate of ?? mongodb.conf bind_ip = 127.0.0.1 does not work but 0.0.0.0 works