1Panel-dev/1Panel · error · Error
failed to drop database ${dbName}
Error message
failed to drop database ${dbName} What it means
Same generated delete script as error 0: after users are dropped, `targetDb.runCommand({ dropDatabase: 1 })` returned `ok !== 1`. In stock MongoDB `dropDatabase` on a non-existent database still returns ok:1, so this failure is a privilege/authentication problem, not a missing-db problem. The error text is produced inside the mongosh eval and propagated as a non-zero docker exec by runMongodbAdminScript (database_mongodb.go:357).
Source
Thrown at agent/app/service/database_mongodb.go:443
});
`, dbNameJSON, usernameJSON, passwordJSON, permissionJSON)), nil
}
func buildMongodbDeleteScript(dbName string) (string, error) {
dbNameJSON, err := json.Marshal(dbName)
if err != nil {
return "", err
}
return strings.TrimSpace(fmt.Sprintf(`
const dbName = %s;
const targetDb = db.getSiblingDB(dbName);
const dropUsersResult = targetDb.runCommand({ dropAllUsersFromDatabase: 1 });
if (!dropUsersResult || dropUsersResult.ok !== 1) {
throw new Error("failed to drop users from " + dbName);
}
const dropDatabaseResult = targetDb.runCommand({ dropDatabase: 1 });
if (!dropDatabaseResult || dropDatabaseResult.ok !== 1) {
throw new Error("failed to drop database " + dbName);
}
`, dbNameJSON)), nil
}
func buildMongodbBindUserScript(dbName, username, password string) (string, error) {
dbNameJSON, err := json.Marshal(dbName)
if err != nil {
return "", err
}
usernameJSON, err := json.Marshal(username)
if err != nil {
return "", err
}
passwordJSON, err := json.Marshal(password)
if err != nil {
return "", err
}
return strings.TrimSpace(fmt.Sprintf(`View on GitHub (pinned to 5ac7c80881)
Solutions
- Inspect the raw failure: run the same script manually in the container and read `codeName`/`errmsg` from the dropDatabase result
- If 'not primary', point the exec at the primary (or step down/fix the set) and retry
- Ensure the stored app-install credential has root or dbAdminAnyDatabase on the auth db
- Retry the 1Panel delete after credentials/privileges are fixed — the preceding dropAllUsersFromDatabase step is idempotent
Example fix
// manual diagnosis inside the container
// mongosh -u root -p <pass> --authenticationDatabase admin --eval \
// 'const r = db.getSiblingDB("mydb").runCommand({dropDatabase:1}); printjson(r)' Defensive patterns
Strategy: try-catch
Validate before calling
// ensure the credential can drop on this db before the flow
// db.getSiblingDB(dbName).runCommand({dropDatabase:1}) is itself the validation; guard instead on roles:
// require role root or dbAdminAnyDatabase in connectionStatus Try / catch
// delete is idempotent (users drop + db drop); safe to retry once after credential fix
if err := deleteFlow(); err != nil {
if isAuthRelated(err) { fixCredential(); err = deleteFlow() }
if err != nil { return fmt.Errorf("drop database %s: %w", dbName, err) }
} Prevention
- For replica sets, run deletes against the primary
- Monitor credential drift: compare stored password with a periodic auth probe
- Treat any ok!==1 as a server-side codeName — always capture docker logs on failure
When it happens
Trigger: Deleting a MongoDB database when the mongosh URI user lacks the `dbAdmin`/`root` role covering the target db; the container's stored password no longer matches; or a replica-set node that is not primary returns 'not primary' via runCommand (ok:0).
Common situations: Non-root user configured at install time; root password rotated outside 1Panel; MongoDB running as a replica set where the exec'd mongosh connects to a secondary; database name containing characters the URI/JS marshaling mangles.
Related errors
- failed to drop users from ${dbName}
- failed to load mongodb user ${userName}
- failed to update mongodb user ${userName}
- failed to list mongodb databases
- failed to load mongodb user privileges
AI-assisted analysis of 1Panel-dev/1Panel@5ac7c80881 (2026-08-15).
Data as JSON: /api/errors/17115f0064e86ae7.
Report an issue: GitHub.