Spring application issues to connect to mongo db - mongodb

Spring boot application.
MongoDb Database hosted on mongodb cloud.
Application propperties
#Database connection string
spring.data.mongodb.host=cluster0.mbdhj.mongodb.net
spring.data.mongodb.port=27017
spring.data.mongodb.database=sample_supplies
spring.data.mongodb.username=user
spring.data.mongodb.password=[my password]
spring.data.mongodb.auto-index-creation=true
Error
com.mongodb.MongoSocketException: No such host is known (cluster0.mbdhj.mongodb.net)
If I use the same host/port/user/password combination with MongoDb Compass, i can connect without issues.
If I use a cluster connection like this
spring.data.mongodb.host=cluster0-shard-00-02.mbdhj.mongodb.net
the application throws error
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
I've opened the firewall, to accept any connection.
Analitics show some actions, but i still get error in Spring.
I was just following a single youtube tutorial. In their example this didn't cause any issue.
What am I doing wrong?
Should I write a class that connects via Java to the database?

Mongo cloud instances do not allow direct connection while debugging

Related

What could I be missing with Prisma client, Cloud Run, and Cloud SQL - my Prisma client can't socket-connect to my Cloud SQL instance DB?

Background
I have a NestJS project with Prisma ORM, and I am continually receiving the error:
PrismaClientInitializationError: Can't reach database server at `localhost`:`5432`
This is happening during the Cloud Build Deploy step.
Since this is a containerized application (attempting to) run in a Cloud Run instance, I'm supposed to use a socket connection. Here's the documentation from Prisma on connecting to a Postgres DB through a socket connection: https://www.prisma.io/docs/concepts/database-connectors/postgresql#connecting-via-sockets
Connecting via sockets
To connect to your PostgreSQL database via sockets, you must add a host field as a query parameter to the connection URL (instead of setting it as the host part of the URI). The value of this parameter then must point to the directory that contains the socket, e.g.: postgresql://USER:PASSWORD#localhost/database?host=/var/run/postgresql/
Note that localhost is required, the value itself is ignored and can be anything.
I've done this to the letter, as described in the Cloud SQL documentation, with the exception that I percent-encoded my path to the directory containing the socket. I've included and excluded the trailing slash.
So my host var looks like this, mapped from the percent-encoded values:
/cloudsql/<MY CLOUD SQL CONNECTION NAME>/<DB>
I've read over the Cloud Run documentation, and in my mind, I should expect a different error if the instance itself can't connect to the Cloud SQL instance. I've followed the "Make sure you have the appropriate permissions and connection" from the documentation a few times now.
Is there anything obvious that I'm missing? Am I wrong about an error related to Cloud Run instance just not connecting with Cloud SQL instance?
Things I've tried & things I know
I CAN connect directly to the Cloud SQL instance locally through psql
I CAN run a local server with the Cloud SQL instance public IP and establish a client connection & interact with the database
I CAN successfully create an image and run a container from that image locally
My big concern
It doesn't make sense to me in which order things should connect to the Cloud SQL instance. To me, the Cloud Run - Cloud SQL connection MUST be established before the application run inside the Cloud Run instance can establish its connection through the socket to the Cloud SQL instance. -- Am I thinking through that correctly?

Not Connected to Server Postgres database , showing timeout expired

I am currently working on Spring Boot project which is connected to Postgres database. I am using PG Admin tool to connected to database. While I am running my project, I am getting exception and that is related to database.
The password I am giving is correct, still it is not connecting to the database. I am not using any AWS services.
How I can resolve this issues related to timeout expired?

Connecting to MongoDB from AWS Glue

I am trying to create a connection from AWS Glue to MongoDB, but when I test the connection it fails with error: "Check that your connection definition references your Mongo database with correct URL syntax, username, and password. Exiting with error code 30". I know that my connection parameters are correct because I can connect with the same host, port, database, user name, and password from another client application (DataGrip). And I know that my VPC configuration should be correct too because I have another connection in the Glue, to connect to the PostgreSQL database on-premise with public IP, that works just fine.
My MongoDB version is 4.4.1. I am out of ideas what else can cause the problem. Is anyone successfully connects to MongoDB form Glue and run the Crawler?

Unable to connect to Mongo DB Atlas using Mule 4 connector

I am trying to connect to mongodb Atlas using Mule 4 connector but it is throwing below error.
I am able to connect to the database through MongoDB Compass.
Any help with this?
Thanks in advance
I was facing this issue. I could resolve this by upgrading the Mongo DB connector of Mulesoft to version 6.3.0, which takes connection string.
This takes DNS, no need to provide multiple server names & port

c3p0 pool cannot establish a connection. How to debug this?

I have a Tomcat and PostgreSQL installed on a server. I'm having a connection problem trying to connect from my servlet to PostgreSQL database using c3p0 pool.
I can reach DB if I'm running Tomcat locally on my laptop. Also I can connect from server to DB using psql (i.e. command line sql utility). But when I'm trying to deploy my servlet to server and establish a connection I'm getting the following error:
java.sql.SQLException: Connections could not be acquired from the underlying database!
com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
...
com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
What should I check to locate a problem? It should be a trivial issue but may be due to 4 a.m. I'm missing something :) Thanks in advance!
PS: Connection from all network interfaces are allowed to database. PostgreSQL JDBC driver and c3p0 pool are distributed in WAR. Tomcat configuration is very default. JNDI is not used.
You need to check a few things:
java.policy which tomcat is using
(e.g.
/etc/tomcat5.5/policy.d/02debian.policy)
db server settings (e.g.
/etc/postgresql/pg_hba.conf)
try connecting without pool first as
in my case c3p0 was hiding important information from me
Adding to #Alexey's answer, I had this issue with Tomcat and PostgreSQL 9.4. In my case, the md5 authentication method in postgres was causing the issue.
If you are using Windows server or RHEL server, make sure you update the authentication method in pg_hba.conf file. Modify it to trust and restart postgresql.