1Panel-dev/1Panel · error · Error
mongodb user not found: ${userName}
Error message
mongodb user not found: ${userName} What it means
The privilege-change script found the user lookup succeeded (ok:1) but `userInfo.users` was empty — the named user does not exist on the database the script is looking at. Unlike errors 7/8 this is a clean negative lookup: usersInfo legitimately returns zero users when the user lives on another db (typically `admin`) or was deleted.
Source
Thrown at agent/app/service/database_mongodb.go:795
permissionJSON, err := json.Marshal(permission)
if err != nil {
return err
}
script := strings.TrimSpace(fmt.Sprintf(`
const dbName = %s;
const userName = %s;
const permission = %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 privileges");
}
if (!Array.isArray(userInfo.users) || userInfo.users.length === 0) {
throw new Error("mongodb user not found: " + userName);
}
const roles = (userInfo.users[0].roles || []).filter(role => role.db !== dbName);
roles.push({ role: permission, db: dbName });
const result = targetDb.runCommand({
updateUser: userName,
roles: roles
});
if (!result || result.ok !== 1) {
throw new Error("failed to update mongodb user privileges");
}
`, databaseJSON, usernameJSON, permissionJSON))
return runMongodbAdminScript(connectionName, script)
}
func loadRemoteMongodbPrivilege(connectionName, dbName, username string) (string, error) {
info, err := loadRemoteMongodbConnection(connectionName)
if err != nil {
return "", errView on GitHub (pinned to 5ac7c80881)
Solutions
- Confirm where the user lives: `db.getSiblingDB("admin").runCommand({usersInfo:{user:"<u>",db:"<db>"}})`
- If deleted, re-create via the bind flow and retry the permission change
- If it lives on admin, either recreate it on the target db or adjust the record so the script targets the owning db
- Check exact username spelling/case against the UI list
Example fix
null
Defensive patterns
Strategy: type-guard
Validate before calling
// resolve the user's home db before the change
// db.getSiblingDB("admin").runCommand({usersInfo:{user:u, db:dbName}}).users.length Type guard
// Go: guard that the user exists on the target db before building the script
func mongodbUserExists(database, dbName, username string) bool {
script := fmt.Sprintf(`print((db.getSiblingDB(%s).runCommand({usersInfo:%s}).users||[]).length)`, dbName, username)
out, err := runMongodbAdminScriptWithStdout(database, script)
return err == nil && strings.TrimSpace(out) == "1"
} Try / catch
if err := changePrivilege(...); err != nil {
if strings.Contains(err.Error(), "mongodb user not found") {
// offer to re-create the user on this db, or re-point the record
}
} Prevention
- Treat usernames as case-sensitive identifiers; copy-paste them
- After deleting a user, refresh the UI list before further edits
When it happens
Trigger: Changing permissions for a user created on the `admin` authenticationDatabase while the script queries the workload db; the user was deleted between the UI listing and the submit; typo/case mismatch in username (MongoDB usernames are case-sensitive).
Common situations: Users provisioned by external tooling on admin; stale UI list after deletion; mixed-case usernames copied from docs.
Related errors
- failed to load mongodb user ${userName}
- failed to update mongodb user password ${userName}
- failed to load mongodb user privileges
- failed to drop users from ${dbName}
- failed to drop database ${dbName}
AI-assisted analysis of 1Panel-dev/1Panel@5ac7c80881 (2026-08-15).
Data as JSON: /api/errors/36f1c3e43af460af.
Report an issue: GitHub.