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.
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.
- In Connection details → Authentication, select Username and password and enter the database user’s credentials.
- Set Authentication database to the database that stores the user. A blank value in Connection details defaults to
admin. - 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_ordersin the URI.authSource=adminin its options. Useadmin or blankin KeplerGrid’s Authentication database field. Passes for the user created in admin.- User created in
keplergrid_auth_users /keplergrid_auth_ordersin the URI.authSource=keplergrid_auth_usersin its options. Usekeplergrid_auth_usersin KeplerGrid’s Authentication database field. Passes for the user created in keplergrid_auth_users.- User created in
keplergrid_auth_users /keplergrid_auth_ordersin the URI.authSource=keplergrid_auth_ordersin its options. Usekeplergrid_auth_ordersin 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
- In a practice connection like the one above, using
keplergrid_auth_ordersas Authentication database fails when the user was created only inkeplergrid_auth_users. Set it back tokeplergrid_auth_usersand click Test connection again. - Once it shows Connection test passed, click Connect and run a read-only query in the intended collection.
- 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.