Unable to connect to mongodb on remote server - mongodb

I have a spring boot application with a mongo database on localhost and everything work fine.
Now i want to deploy my application to my server and the database is on another remote server.
I changed mongod.conf file and uncommented “bindIp: 0.0.0.0 #default value is 127.0.0.1”
In my application.properties file i have this:
“spring.data.mongodb.uri=mongodb://172.16.4.26:27017/jenkinsdb”
When i run my application i get “com.mongodb.MongoSocketOpenException: Exception opening socket” caused by “Caused by: java.net.SocketTimeoutException: connect timed out”

It seems like MongoDB is not accessible over a network there might be several reasons. I have listed some:
MongoDB port 27017 is not open
Firewall is blocking the connection with another machine
You can also try adding the authentication information in your URI like this:
spring.data.mongodb.uri=mongodb://user:secret#mongo1.example.com:12345,mongo2.example.com:23456/test
OR
you can split it over multiple properties
spring.data.mongodb.host=mongoserver.example.com
spring.data.mongodb.port=27017
spring.data.mongodb.database=test
spring.data.mongodb.username=user
spring.data.mongodb.password=secret
If you want to check whether there is a problem with the application or MongoDB you can spin up the free Mongo Atlas instance and try to connect that with your application if that works then there will be surely a connectivity issue with our machine

Related

Connect to mongodb via ssh tunnel failing

I have tried to connect to my mongodb on a server i own via an ssh tunnel via the following apps but nothing will connect:
compass
robomongo
nosqlbooster4mongo
phpstorm inbuilt mongodb java connector
Server and mongo:
Server: ubuntu 18lts
Mongo: latest community version
The Connection URL in all instances is the same (also tried removing the query params) and this url works on the node app:
mongodb://localhost:27017/data-aggregator?retryWrites=true&w=majority
nosqlbooster4mongo's error message is:
But the connection url is 27017 and gets changed to 37903 for some reason
PHPStorm's error message is:
DBMS: Mongo DB Case sensitivity: plain=mixed, delimited=mixed Driver:
MongoDB JDBC Driver (ver. 1.13, JDBC4.2) Effective version: UNKNOWN
(ver. 0.0) Ping: 10 sec, 289 ms (keep-alive query results in error)
Timed out after 10000 ms while waiting to connect. Client view of
cluster state is {type=UNKNOWN, servers=[{address=localhost:42865,
type=UNKNOWN, state=CONNECTING,
exception={com.mongodb.MongoSocketReadException: Exception receiving
message}, caused by {java.net.SocketException: Connection reset}}].
Nothing works but i cannot understand why.
The SSH connection is working as confirmed by nosqlbooster4mongo and phpstorm
But as soon as it then tries to connect to the local mongodb instance it fails. I don't know if this is an issue with the SSH tunnel or the mongo setup. Via a terminal i can connect to mongo no issue, also the node app there can too.
The tunnels are using the same key as i use to connect to the server via terminal without issue which leads me to believe it is mongo but i don't know where to look :/
As the tunnel is established, then this says the server firewalls are not an issue.
I don't know what it is, is there an additional query param for ssh tunnel access?
Solved by #Jack_Woehr on: https://www.mongodb.com/community/forums/t/mongo-5-community-edition-cannot-connect-via-tunnel/151526
The trick was to not use the ssh tunnel from any of the tools listed and just create a the tunnel on the OS.

Problem to connect mongo DB replica set from linux, single instance run ok. Using .net core mongo driver

I am trying to connect an application in .net core from a linux machine to a mongo replicaset. But I am getting a timeout error.
Unhandled exception. System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector
The replica ips are accessible from this machine, a response is obtained by pinging.
If in linux the connection to mongo is to a single instance of the replica, it works correctly.
This same code in windows connects without problem.
If you are certain IP connectivity works, most likely you have the hostnames wrong. The hostnames used in RS config must work from each client.
See https://github.com/p-mongo/mongodb-faq.

Linking mongoDB to elasticbeanstalk application

So I have this problem where my node application that is ran by Docker in elasticbeanstalk cant establish a connection with mongoDB instance that is in another elasticbeanstalk environment under the same application(it deployed and ran with Docker aswell).
I have made sure that both of them are in the same VPC and that the mongoDB instance accepts inbound connections from the security group that the node application is under(inbound connections are accepted on port 27017).
Node application uses mongoDBs private IP in the connection string. Should work because they are in the same VPC.
Somehow the node application cant connect to the mongoDB instance and it throws the same error always.
*** DATABASE ERROR: MongoNetworkError: failed to connect to server [private-ip-here:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND private-ip-here private-ip-here:27017] ***
Can anyone give me advice what am I doing wrong ?
Most likely reason would be not configuring mongod.config file in etc directory.
There would be something like :
net:
bindIp: 127.0.0.1
Comment the bindIP or replace it with your server's IP Address.

PGAdmin III cannot connect AWS RDS

I am trying to connect AWS RDS PostgreSql from PgAdmin 3. I followed the below link
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToPostgreSQLInstance.html
In Security Group, I also added PostgreSQL and All traffic as below
The "publicly accessible" flag was enabled (updated after Mark B's comment)
I got the error from PGAdmin3
Very appreciate for any suggestion
******UPDATE*******
I can connect pgAdminIII to AWS RDS successfully using home wifi, but cannot connect using office wifi.
My concern is:
Was the port 5432 blocked by office wifi?
How can I configure/update the port without impacting to current API?
Note: My current API is working well (CRUD)
Can you can test your connection to a DB instance using common Linux or Windows tools first?
From a Linux or Unix terminal, you can test the connection by typing the following (replace with the endpoint and with the port of your DB instance):
$nc -zv DB-instance-endpoint port
For example, the following shows a sample command and the return value:
$nc -zv postgresql1.c6c8mn7tsdgv0.us-west-2.rds.amazonaws.com 8299
Connection to postgresql1.c6c8mn7tsdgv0.us-west-2.rds.amazonaws.com
8299 port [tcp/vvr-data] succeeded!
Windows users can use Telnet to test the connection to a DB instance. Note that Telnet actions are not supported other than for testing the connection. If a connection is successful, the action returns no message. If a connection is not successful, you receive an error message such as the following:
C:>telnet sg-postgresql1.c6c8mntzhgv0.us-west-2.rds.amazonaws.com
8299
Connecting To sg-postgresql1.c6c8mntzhgv0.us-west-2.rds.amazonaws.com...Could not
open connection to the host, on port 819: Connect failed
If Telnet actions return success, then you are good to go.
If you are trying to access it from a network which is not listed for that port. you need to add inbound rules for those network IPs from AMAZON RDS system
You will also need to set Public accessibility true under Connect & security tab in RDS console.
Read this post.In your security group go to unbound rules and add my ip.
and make sure your database is public.
https://serverfault.com/questions/656079/unable-to-connect-to-public-postgresql-rds-instance

mongodb could not connect to server

I'm new to MongoDB. I'm trying to connect to my remote mongo database from my work machine( I tried for both mongohq as well as mongolab). I'm getting the error listed below. When I run the same command from my home machine it runs fine and does connect to remove mongo database. I'm not sure what is messed up on my work machine but I'd like to fix it. Thanks for you help.
MongoDB shell version: 2.4.9
connecting to: linus.mongohq.com:10097/mydb
Thu Jan 16 04:16:02.689 Error: couldn't connect to server linus.mongohq.com:10097
at src/mongo/shell/mongo.js:147
exception: connect failed
As per question comments, your mongo shell client can't connect to the mongo instance. Assuming that your internet connectivity is fine, the most common reason for the failure is that the ports are blocked on your network.
Some ISPs automatically block these ports by default as an additional security protection for users that don't need them open. Contact your ISP or network admin, they should be able to help you out.