1Panel-dev/1Panel · error · Error
failed to load mongodb user ${userName}
Error message
failed to load mongodb user ${userName} What it means
First guard in buildMongodbBindUserScript (database_mongodb.go:472): `targetDb.runCommand({ usersInfo: userName })` returned a falsy result or `ok !== 1`. The script uses usersInfo to decide between createUser and updateUser, so this failure aborts before any write. ok:0 here typically means the authenticated user cannot view users on that db (requires viewUser privilege) or the command was rejected due to auth.
Source
Thrown at agent/app/service/database_mongodb.go:472
if err != nil {
return "", err
}
passwordJSON, err := json.Marshal(password)
if err != nil {
return "", err
}
return strings.TrimSpace(fmt.Sprintf(`
const dbName = %s;
const userName = %s;
const password = %s;
const targetDb = db.getSiblingDB(dbName);
const userInfo = targetDb.runCommand({
usersInfo: userName,
showCredentials: false,
showCustomData: false
});
if (!userInfo || userInfo.ok !== 1) {
throw new Error("failed to load mongodb user " + userName);
}
const roles = [{ role: "readWrite", db: dbName }];
if (Array.isArray(userInfo.users) && userInfo.users.length > 0) {
const result = targetDb.runCommand({
updateUser: userName,
pwd: password,
roles: roles
});
if (!result || result.ok !== 1) {
throw new Error("failed to update mongodb user " + userName);
}
} else {
const result = targetDb.runCommand({
createUser: userName,
pwd: password,
roles: roles
});
if (!result || result.ok !== 1) {View on GitHub (pinned to 5ac7c80881)
Solutions
- Check the container credential's roles with connectionStatus (see error 0) and fix it to root/userAdminAnyDatabase if limited
- Run `db.getSiblingDB("<db>").runCommand({usersInfo:"<user>", showCredentials:false})` manually and read the error
- If the admin credential is wrong, correct username/password on the 1Panel database connection record and re-run bind
Example fix
// manual probe
// mongosh -u root -p <pass> --authenticationDatabase admin --eval \
// 'printjson(db.getSiblingDB("mydb").runCommand({usersInfo:"appuser",showCredentials:false}))' Defensive patterns
Strategy: validation
Validate before calling
// pre-check visibility of the user before binding
script := fmt.Sprintf(`const r=db.getSiblingDB(%s).runCommand({usersInfo:%s,showCredentials:false}); print(r.ok)`, dbNameJSON, userJSON)
out, err := runMongodbAdminScriptWithStdout(database, script) // expect "1" Try / catch
if err := bindMongodbUser(...); err != nil {
if strings.Contains(err.Error(), "failed to load mongodb user") {
// credential/privilege problem: show roles check output, not the raw string
}
} Prevention
- Use root for the container's admin connection; scope app users instead
- Keep user creation and the admin credential on the same authenticationDatabase
When it happens
Trigger: bindMongodbUser (database_mongodb.go:335) invoked with a `from` of local while the stored container credential lacks userAdmin/viewUser on dbName; mongosh connected to a db where the user is not visible; authentication failed so runCommand results degrade.
Common situations: Bind/create user flow run right after install with a custom (non-root) admin user; password for the admin account changed directly in MongoDB after install; user exists on the `admin` authenticationDatabase instead of the target db.
Related errors
- failed to drop users from ${dbName}
- failed to drop database ${dbName}
- failed to load mongodb user privileges
- failed to update mongodb user ${userName}
- failed to list mongodb databases
AI-assisted analysis of 1Panel-dev/1Panel@5ac7c80881 (2026-08-15).
Data as JSON: /api/errors/83ecc3190d22d89d.
Report an issue: GitHub.