Reactive Scala Driver for MongoDB

Asynchronous & Non-Blocking

MongoDB Atlas

Atlas is the official cloud MongoDB service (feature complete and up-to-date).

Once the Atlas account is set up (with a Cluster and Security/users), then the connection is accessible.

MongoDB Atlas Cluster

In the shown dialog, the “Connect your Application” can be selected as method.

MongoDB Atlas Connection method

Then the connection URI is displayed, and can be copied with user/password placeholders.

MongoDB Atlas Connection URI

First check the MongoShell can connect using the URI:

export ATLAS_USERNAME="..."
export ATLAS_PASSWORD="..."

mongo -u "${ATLAS_USERNAME}" -p "${ATLAS_PASSWORD}" "mongodb+srv://...-cluster-ej8gu.azure.mongodb.net/<dbname>?retryWrites=true&w=majority"

In order to substitute the placeholders ATLAS_USERNAME and ATLAS_PASSWORD, actual users can be check in the Database Access.

MongoDB Database Access

Check whether one of the following errors is seen while trying to connect with the MongoShell.

Unable to reach primary for set ...-cluster-shard-0
Cannot reach any nodes for set ...-cluster-shard-0.
...
Please check network connectivity and the status of the set.

If such error happens, then it’s required to check the Network Access to make sure the source address is authorized; At least one entry must be annotated with “includes your current IP address”.

MongoDB Network Access

If the following error is displayed by the MongoShell, then the credentials must be checked.

can't authenticate against replica set ... caused by :: Authentication failed

When the MongoShell is successfully connected, the application configuration can be defined as below.

mongodb.uri = "mongodb+srv://${ATLAS_USERNAME}:${ATLAS_PASSWORD}@...-cluster-ej8gu.azure.mongodb.net/<dbname>?retryWrites=true&w=majority&authenticationDatabase=admin"

Note: The URI is DNS seedlist format, supported by ReactiveMongo. The parameter authenticationDatabase=admin must be appended.

It’s necessary to make sure that the user is granted the appropriate permissions.

MongoDB Atlas User

See the documentation

Suggest changes