Connect a mongo atlas connection to play framework app

328 Views Asked by At

I can successfully connect a standalone cluster to my Play Framework (2.7) app (with ReactiveMongo 0.17.1) and I can connect Mongo Compass to my replica set (created in MongoDb Atlas) but am having big problems connecting my MongoDb Atlas replica set to my Play Framework app. This should be a case of using the connection string in the application.conf file; i.e.

mongodb.uri = <connectionString>

In fact the ReactiveMongo documentation describes it as:

mongodb.uri = "mongodb+srv://${ATLAS_USERNAME}:${ATLAS_PASSWORD}@cluster0-p8ccg.mongodb.net/test?retryWrites=true&w=majority"

  • with 3 variables of ${ATLAS_USERNAME}, ${ATLAS_PASSWORD} & test (default database name)

And the MongoDb Atlas documentation (when logged in) describes the connection string as being formulated like so:

mongodb+srv://<username>:<password>@cluster0.pwe0y.mongodb.net/myFirstDatabase?retryWrites=true&w=majority

  • with 3 variables of <username>, <password> & myFirstDatabase (default database name)

So aside from some variable differences in the addresses (I use the one from Atlas as it is distinctive to my details)

The recurring error reads:

[error] r.c.a.MongoDBSystem - [Supervisor-1/Connection-2] Fails to send a isMaster request to cluster0-shard-00-01.pwe0y.mongodb.net:27017 (channel #ac1cfe76) javax.net.ssl.SSLException: SSLEngine closed already at reactivemongo.io.netty.handler.ssl.SslHandler.wrap(...)(Unknown Source)

Things to note:

  • I have node.js v12.14.1
  • the user is granted the appropriate permissions
  • option parameters have also been URL encoded tested
  • my ip address is in the IP Access List (in Mongo Atlas)
2

There are 2 best solutions below

0
S H A S H A N K On

For connection you should just pass the mongodb.uri as this:

mongodb.uri = "mongodb+srv://${ATLAS_USERNAME}:${ATLAS_PASSWORD}@cluster0-p8ccg.mongodb.net"

don't use the full connection string URL for the connection.

0
cchantep On

If Atlas doesn't set authSource=admin in the DNS SRV, make sure the add ?authSource=admin to the connection URI.

Also note that, 0.17 is more than two years old, won't get fix.