bytebase/bytebase · error

cannot get version from buildInfo command result

Error message

cannot get version from buildInfo command result

What it means

getVersion runs the buildInfo command against the MongoDB server and reads the "version" field from the raw result map. Because the result is an untyped bson.M, the code checks the key exists before asserting it. This error is thrown when the buildInfo response contains no "version" field, indicating a server that does not behave like a standard MongoDB deployment.

Source

Thrown at backend/plugin/db/mongodb/sync.go:269

	}
	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 {
		return false, errors.Wrap(err, "failed to list database names")
	}
	for _, database := range databaseList {
		if database == databaseName {

View on GitHub (pinned to 1870550677)

Solutions

  1. Run db.runCommand({buildInfo: 1}) in mongosh against the same endpoint and confirm the version field is present
  2. Check whether a proxy, sidecar, or security gateway is rewriting command responses; bypass it to compare raw output
  3. Ensure the target service is MongoDB or a fully compatible derivative; DocumentDB/FerretDB both return version, so a missing field signals an unusual intermediary
  4. Return a safe default version (or log and continue) rather than failing schema sync, since version is advisory metadata

Example fix

// before
version, ok := commandResult["version"]
if !ok {
	return "", errors.New("cannot get version from buildInfo command result")
}
// after
version, ok := commandResult["version"]
if !ok {
	slog.Warn("buildInfo result missing version field")
	return "0.0.0", nil
}
Defensive patterns

Strategy: validation

Validate before calling

var res bson.M
if err := db.RunCommand(ctx, bson.D{{Key:"buildInfo", Value: 1}}).Decode(&res); err != nil {
	return err
}
if _, ok := res["version"]; !ok {
	return fmt.Errorf("endpoint does not report a buildInfo version")
}

Type guard

func hasVersion(res bson.M) bool {
	_, ok := res["version"]
	return ok
}

Try / catch

if err := driver.SyncDBSchema(ctx); err != nil {
	if strings.Contains(err.Error(), "cannot get version from buildInfo command result") {
		// proceed without version metadata; it is advisory
		return nil
	}
	return err
}

Prevention

When it happens

Trigger: SyncDBSchema → getVersion: database.RunCommand(ctx, {buildInfo: 1}) succeeds but the decoded result lacks the "version" key — e.g. a proxy or emulation layer returning a partial buildInfo document.

Common situations: Connecting through proxies or shims that strip fields from buildInfo; non-MongoDB compatible services (custom gateways, stripped sandboxes); intercepting middleware that rewrites command responses.

Related errors


AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06). Data as JSON: /api/errors/5bf061fe9594957f. Report an issue: GitHub.