1
votes

Trying to connect to cosmosdb Mongo API using Primary Connection String and UserName(Database Name)

Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@3c291aad. Client view of cluster state is {type=REPLICA_SET, servers=[{address=**********.documents.azure.com:10255, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {java.net.SocketException: Connection reset}}] at com.mongodb.internal.connection.BaseCluster.createTimeoutException(BaseCluster.java:401) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.internal.connection.BaseCluster.selectServer(BaseCluster.java:120) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.internal.connection.MultiServerCluster.selectServer(MultiServerCluster.java:54) ~[mongodb-driver-core-3.8.2.jar:na] at com.mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:138) ~[mongodb-driver-3.8.2.jar:na] at com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:94) ~[mongodb-driver-3.8.2.jar:na] at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.getClientSession(MongoClientDelegate.java:249) ~[mongodb-driver-3.8.2.jar:na] at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:190) ~[mongodb-driver-3.8.2.jar:na] at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:960) ~[mongodb-driver-3.8.2.jar:na] at com.mongodb.client.internal.MongoCollectionImpl.executeDelete(MongoCollectionImpl.java:940) ~[mongodb-driver-3.8.2.jar:na] at com.mongodb.client.internal.MongoCollectionImpl.deleteMany(MongoCollectionImpl.java:551) ~[mongodb-driver-3.8.2.jar:na] at org.springframework.data.mongodb.core.MongoTemplate$9.doInCollection(MongoTemplate.java:1729) ~[spring-data-mongodb-2.1.9.RELEASE.jar:2.1.9.RELEASE] at org.springframework.data.mongodb.core.MongoTemplate$9.doInCollection(MongoTemplate.java:1689) ~[spring-data-mongodb-2.1.9.RELEASE.jar:2.1.9.RELEASE] at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:545) ~[spring-data-mongodb-2.1.9.RELEASE.jar:2.1.9.RELEASE] ... 30 common frames omitted

2
Tried multiple ways but getting this exception, has anyone faced the sameArnav Karforma

2 Answers

0
votes

Please follow the example github project in the link below and you will be able to connect.

https://github.com/Azure-Samples/azure-cosmos-db-mongodb-spring

0
votes

Try with MongoDB driver 3.7.1 or earlier. It appears that’s there’s an issue with MongoDB driver for Java 3.8.0 and above and the way Cosmos DB takes the MongoDB protocol.