Struggling to connect my SpringBoot project to MongoDB atlas

I am trying to implement Authentication to my Springboot project using JWT. I am using MongoDB Atlas. The only error I am getting is a com.mongodb.MongoSocketOpenException error. I have looked at several forums and I am not sure what to do.

This is the error log:

2024-01-04T16:10:13.169-05:00  INFO 13144 --- [127.0.0.1:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server 127.0.0.1:27017

com.mongodb.MongoSocketOpenException: Exception opening socket
        at com.mongodb.internal.connection.SocketStream.lambda$open$0(SocketStream.java:84) ~[mongodb-driver-core-4.11.1.jar:na]
        at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[na:na]
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:84) ~[mongodb-driver-core-4.11.1.jar:na]
        at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:211) ~[mongodb-driver-core-4.11.1.jar:na]
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:196) ~[mongodb-driver-core-4.11.1.jar:na]
        at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:156) ~[mongodb-driver-core-4.11.1.jar:na]
        at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: java.net.ConnectException: Connection refused: no further information
        at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
        at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[na:na]
        at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542) ~[na:na]
        at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597) ~[na:na]
        at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[na:na]
        at java.base/java.net.Socket.connect(Socket.java:633) ~[na:na]
        at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:76) ~[mongodb-driver-core-4.11.1.jar:na]
        at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:104) ~[mongodb-driver-core-4.11.1.jar:na]
        at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:78) ~[mongodb-driver-core-4.11.1.jar:na]
        ... 4 common frames omitted

This is my application.properties file:

spring.data.mongodb.uri=mongodb+srv://<username>:<password><@cluster-url>/?retryWrites=true&w=majority
spring.data.mongodb.database=users

Hello,
The com.mongodb.MongoSocketOpenException error indicates a connection issue to MongoDB. Ensure your application.properties file correctly configures the MongoDB URI for Atlas, like spring.data.mongodb.uri=mongodb+srv://:@/myDatabase?retryWrites=true&w=majority. Verify that your IP address is whitelisted in MongoDB Atlas’ network access settings. Also, check for any typographical errors in your configuration, ensure DNS resolves the cluster URL properly, and confirm you have the correct MongoDB driver dependencies in your project.