1Panel-dev/1Panel · error · Error
failed to update mongodb user ${userName}
Error message
failed to update mongodb user ${userName} What it means
In buildMongodbBindUserScript, usersInfo succeeded and found the user, but the follow-up `updateUser` (new pwd + readWrite role) returned `ok !== 1`. updateUser fails with ok:0 when the caller lacks grant/rename/changePassword privileges for that user, when the new password violates the server's password validation/dictionary rules, or when the user actually lives on a different database than the one being updated.
Source
Thrown at agent/app/service/database_mongodb.go:482
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) {
throw new Error("failed to create mongodb user " + userName);
}
}
`, dbNameJSON, usernameJSON, passwordJSON)), nil
}
func buildMongodbPasswordScript(dbName, username, password string) (string, error) {
dbNameJSON, err := json.Marshal(dbName)
if err != nil {
return "", errView on GitHub (pinned to 5ac7c80881)
Solutions
- Run the updateUser manually and read `codeName` (e.g. AuthenticationFailed/Password fails validation) to get the exact cause
- If password validation rejects it, generate a longer/stronger password in the 1Panel form and retry
- Verify the user's actual home db with usersInfo on admin, and update it there if it differs
- Confirm the admin credential has userAdmin on the db that owns the user
Example fix
// before: password that fails server policy updateMongodbPassword(..., "aB1!") // after: length/policy-compliant generated secret updateMongodbPassword(..., "xK7#mQ9$vL2pW8zR")
Defensive patterns
Strategy: validation
Validate before calling
// client-side: enforce server password policy before submitting
if len(password) < 8 || !hasUpper(password) || !hasDigit(password) { return errors.New("password too weak for server policy") } Try / catch
if err := bindMongodbUser(...); err != nil {
if strings.Contains(err.Error(), "failed to update mongodb user") {
// suggest password policy / privilege fix, keep original input for retry
}
} Prevention
- Generate passwords with 1Panel's generator (length ≥ 16, mixed classes)
- After any bind failure, re-check usersInfo before retrying so state is known
When it happens
Trigger: bindMongodbUser on an existing user whose password fails MongoDB's configured passwordValidationRegex; the exec'd admin user has viewUser but not userAdmin; attempting updateUser on `db` when the user was created on `admin`.
Common situations: Generated or short passwords rejected by a hardened password policy; custom non-root admin; users provisioned by an external tool on the admin db.
Related errors
- failed to update mongodb user password ${userName}
- failed to drop users from ${dbName}
- failed to drop database ${dbName}
- failed to load mongodb user ${userName}
- failed to create mongodb user ${userName}
AI-assisted analysis of 1Panel-dev/1Panel@5ac7c80881 (2026-08-15).
Data as JSON: /api/errors/266e18a8828f01b6.
Report an issue: GitHub.