t8y2/dbx · error · java.lang.IllegalStateException
MongoDB server version not found
Error message
MongoDB server version not found
What it means
After running the buildInfo command, the agent extracts the "version" field to report the MongoDB server version. If buildInfo comes back without a usable version string (null or blank), serverVersionFromBuildInfo throws IllegalStateException. This indicates an unexpected or non-standard server response rather than a user input problem.
Source
Thrown at agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java:961
private static Object runCommand(JsonObject params) {
MongoClient c = requireClient();
String database = params.get("database").getAsString();
Document command = documentOrNull(params, "command_json");
if (command == null || command.isEmpty()) {
throw new IllegalArgumentException("runCommand requires a non-empty command document");
}
Document response = c.getDatabase(database).runCommand(command);
List<Map<String, Object>> documents = new ArrayList<>();
documents.add(bsonToJson(response));
List<JsonObject> extendedDocuments = new ArrayList<>();
extendedDocuments.add(bsonToExtendedJson(response));
return documentQueryResultWithExtended(documents, extendedDocuments, 1);
}
static String serverVersionFromBuildInfo(Document buildInfo) {
String version = buildInfo.getString("version");
if (version == null || version.isBlank()) {
throw new IllegalStateException("MongoDB server version not found");
}
return version;
}
static boolean serverVersionRequiresSerialDropIndexes(String version) {
if (version == null) {
return false;
}
int start = 0;
while (start < version.length() && !Character.isDigit(version.charAt(start))) {
start++;
}
String[] components = version.substring(start).split("\\.", 3);
if (components.length < 2) {
return false;
}
try {
int major = Integer.parseInt(components[0]);View on GitHub (pinned to c0390bff16)
Solutions
- Run {buildInfo: 1} directly against the server (e.g. via mongosh) and inspect the returned "version" field.
- Confirm you are connected to a genuine MongoDB server, not a proxy or incompatible service.
- Check driver/server connectivity and that the admin database is reachable; retry the version command.
Defensive patterns
Strategy: try-catch
Type guard
function hasServerVersion(buildInfo) {
return buildInfo != null && typeof buildInfo.version === "string" && buildInfo.version.trim() !== "";
} Try / catch
try {
const version = await agent.serverVersion();
} catch (e) {
if (String(e.message).includes("MongoDB server version not found")) {
// fall back to raw runCommand({buildInfo: 1}) and log the raw response for diagnosis
} else throw e;
} Prevention
- Connect to a genuine MongoDB server, not a proxy that rewrites responses.
- Verify buildInfo output in mongosh when onboarding an environment.
- Log the raw buildInfo response when version detection fails.
When it happens
Trigger: Calling a version-check command against a server whose buildInfo response lacks a "version" field, or against a proxy/wire-compat layer that strips or renames it; a mocked/stubbed buildInfo document in tests.
Common situations: Connecting through a non-MongoDB compatible proxy; very old or exotic servers; test fixtures returning partial buildInfo documents; permissions setups where command responses are altered.
Related errors
- Client certificate and key must be provided together
- MongoDB aggregate option explain must be a boolean
- MongoDB aggregate option cursor must be an object
- Unsupported MongoDB aggregate cursor option: ${key}
- MongoDB aggregate option collation must be an object
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/2190f354da9975d8.
Report an issue: GitHub.