KeplerGrid guide

Fix MongoDB authentication failed errors

Use Test connection to see which step failed. If the failure is authentication, start with the database where the user was created and how you entered its credentials.

Read the failed connection check

In File → New Connection…, enter your connection details and click Test connection. Read the failed check in the result. If it names Authentication, check the user, authentication database and mechanism. If it names DNS, MongoDB connection, TLS or SSH tunnel, address that connection step first.

The test uses a temporary connection. You can correct the inputs and test again in the same dialog.

KeplerGrid reports Connection test failed and shows the Authentication check
The synthetic connection reached MongoDB, but the wrong authentication database produced an Authentication failure.

Use the database where the user was created

The database where MongoDB verifies the user’s credentials can differ from the one holding the documents. For example, a practice user created in keplergrid_auth_users can have read access to keplergrid_auth_orders.

  1. In Connection details → Authentication, select Username and password and enter the database user’s credentials.
  2. Set Authentication database to the database that stores the user. A blank value in Connection details defaults to admin.
  3. Set Default database in Options if you want to start in a specific database. Use Automatic (SCRAM) unless your server administrator specifies a mechanism.

If you use Connection string, set authSource explicitly when your login and data databases differ. This illustrative URI uses the data database in the path and the login database in the option.

mongodb://orders_reader:ENCODED_PASSWORD@127.0.0.1:27017/keplergrid_auth_orders?authSource=keplergrid_auth_users

How authSource maps to KeplerGrid

The URI path is the default data database. With SCRAM username and password authentication, a standard URI without authSource uses that path for authentication, or admin if the path is empty.

User created in admin
/keplergrid_auth_orders in the URI. authSource=admin in its options. Use admin or blank in KeplerGrid’s Authentication database field. Passes for the user created in admin.
User created in keplergrid_auth_users
/keplergrid_auth_orders in the URI. authSource=keplergrid_auth_users in its options. Use keplergrid_auth_users in KeplerGrid’s Authentication database field. Passes for the user created in keplergrid_auth_users.
User created in keplergrid_auth_users
/keplergrid_auth_orders in the URI. authSource=keplergrid_auth_orders in its options. Use keplergrid_auth_orders in KeplerGrid’s Authentication database field. Authentication fails for the second user.
Set up the practice connection

On a disposable self-managed MongoDB server with authentication enabled, open mongosh as a practice administrator. Use fresh databases. At the password prompt, create a synthetic password with a reserved character such as @ or #.

const orders = db.getSiblingDB("keplergrid_auth_orders");
const ids = db.getSiblingDB("keplergrid_auth_users");
orders.orders.insertOne({ _id: "ORD-1", status: "paid" });
ids.createUser({
  user: "orders_reader",
  pwd: passwordPrompt(),
  roles: [{ role: "read", db: "keplergrid_auth_orders" }]
});

Encode credentials once in a raw URI

In a raw URI, percent-encode reserved characters inside the username and password. For example, the illustrative password Example@Only#1 becomes Example%40Only%231 in that part of the URI. Leave the URI separators intact.

In separate Database username and Database password fields, enter the raw credentials. KeplerGrid encodes them for you. For MongoDB Atlas, use the Atlas database user and keep the connection options supplied by Atlas.

Confirm the corrected settings

  1. In a practice connection like the one above, using keplergrid_auth_orders as Authentication database fails when the user was created only in keplergrid_auth_users. Set it back to keplergrid_auth_users and click Test connection again.
  2. Once it shows Connection test passed, click Connect and run a read-only query in the intended collection.
  3. If the query itself returns permission denied, check which roles the user has on that database or collection. Successfully authenticating gives the server your identity. MongoDB checks access to the collection separately.

Connect to MongoDB Atlas or check who can access a MongoDB collection.