bytebase/bytebase · error
cannot run buildInfo command
Error message
cannot run buildInfo command
What it means
getVersion runs the buildInfo administrative command against the "admin" database (bytebaseDefaultDatabase) to learn the server version. If RunCommand fails, the error is wrapped as "cannot run buildInfo command". Bytebase needs the version to tailor instance behavior, so instance sync cannot proceed without it.
Source
Thrown at backend/plugin/db/mongodb/sync.go:265
}
slices.Sort(indexNames)
for _, name := range indexNames {
indexes = append(indexes, indexMap[name])
}
return indexes, nil
}
func isSystemCollection(collectionName string) bool {
return strings.HasPrefix(collectionName, "system.")
}
// getVersion returns the version of mongod or mongos instance.
func (d *Driver) getVersion(ctx context.Context) (string, error) {
database := d.client.Database(bytebaseDefaultDatabase)
var commandResult bson.M
command := bson.D{{Key: "buildInfo", Value: 1}}
if err := database.RunCommand(ctx, command).Decode(&commandResult); err != nil {
return "", errors.Wrap(err, "cannot run buildInfo command")
}
version, ok := commandResult["version"]
if !ok {
return "", errors.New("cannot get version from buildInfo command result")
}
v, ok := version.(string)
if !ok {
return "", errors.New("cannot convert version to string")
}
return v, nil
}
// isDatabaseExist returns true if the database exists.
func (d *Driver) isDatabaseExist(ctx context.Context, databaseName string) (bool, error) {
// We do the filter by hand instead of using the filter option of ListDatabaseNames because we may encounter the following error:
// Unallowed argument in listDatabases command: filter
databaseList, err := d.client.ListDatabaseNames(ctx, bson.M{})
if err != nil {View on GitHub (pinned to 1870550677)
Solutions
- Grant the connection user the clusterMonitor role on the admin database (buildInfo requires it on secured clusters).
- Confirm the connection string points at a reachable mongod/mongos and the admin DB exists.
- Retry after checking network/firewall stability between Bytebase and MongoDB.
- Check mongod logs for the authorization failure and adjust roles accordingly.
Example fix
// before: user with only read role fails buildInfo
// after: in mongo shell
use admin
db.grantRolesToUser("bytebase", [{ role: "clusterMonitor", db: "admin" }]) Defensive patterns
Strategy: try-catch
Validate before calling
// confirm the user can run buildInfo before opening the driver
var result bson.M
err := adminDB.RunCommand(ctx, bson.D{{Key: "buildInfo", Value: 1}}).Decode(&result)
// err != nil means grant clusterMonitor on admin first Try / catch
version, err := d.getVersion(ctx)
if err != nil {
var cmdErr mongo.CommandError
if errors.As(err, &cmdErr) && cmdErr.Code == 13 {
// authorization failure: grant clusterMonitor on admin
}
return err
} Prevention
- Always grant clusterMonitor on admin to the Bytebase MongoDB user.
- Test the connection string with the mongo shell using the same credentials.
- Watch for network drops during instance connection setup.
When it happens
Trigger: database.RunCommand(ctx, bson.D{{"buildInfo", 1}}) fails during driver Open/instance sync: the connected user lacks permission to run buildInfo, the connection was dropped, or a mongos/router rejected the command.
Common situations: Locked-down MongoDB deployments where the bytebase user has only read roles on one database; connecting through a proxy that disallows admin commands; server shutdown or network interruption during connection setup.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- cannot get version from buildInfo command result
- cannot convert version to string
- cannot run usersInfo command
- failed to list collection names
- failed to get estimated document count
AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06).
Data as JSON: /api/errors/4c7e940db5ce4dc6.
Report an issue: GitHub.