{"record":{"id":"2190f354da9975d8","repo":"t8y2/dbx","slug":"mongodb-server-version-not-found","errorCode":null,"errorMessage":"MongoDB server version not found","messagePattern":"MongoDB server version not found","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":961,"sourceCode":"    private static Object runCommand(JsonObject params) {\n        MongoClient c = requireClient();\n        String database = params.get(\"database\").getAsString();\n        Document command = documentOrNull(params, \"command_json\");\n        if (command == null || command.isEmpty()) {\n            throw new IllegalArgumentException(\"runCommand requires a non-empty command document\");\n        }\n        Document response = c.getDatabase(database).runCommand(command);\n        List<Map<String, Object>> documents = new ArrayList<>();\n        documents.add(bsonToJson(response));\n        List<JsonObject> extendedDocuments = new ArrayList<>();\n        extendedDocuments.add(bsonToExtendedJson(response));\n        return documentQueryResultWithExtended(documents, extendedDocuments, 1);\n    }\n\n    static String serverVersionFromBuildInfo(Document buildInfo) {\n        String version = buildInfo.getString(\"version\");\n        if (version == null || version.isBlank()) {\n            throw new IllegalStateException(\"MongoDB server version not found\");\n        }\n        return version;\n    }\n\n    static boolean serverVersionRequiresSerialDropIndexes(String version) {\n        if (version == null) {\n            return false;\n        }\n        int start = 0;\n        while (start < version.length() && !Character.isDigit(version.charAt(start))) {\n            start++;\n        }\n        String[] components = version.substring(start).split(\"\\\\.\", 3);\n        if (components.length < 2) {\n            return false;\n        }\n        try {\n            int major = Integer.parseInt(components[0]);","sourceCodeStart":943,"sourceCodeEnd":979,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L943-L979","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function hasServerVersion(buildInfo) {\n  return buildInfo != null && typeof buildInfo.version === \"string\" && buildInfo.version.trim() !== \"\";\n}","tryCatchPattern":"try {\n  const version = await agent.serverVersion();\n} catch (e) {\n  if (String(e.message).includes(\"MongoDB server version not found\")) {\n    // fall back to raw runCommand({buildInfo: 1}) and log the raw response for diagnosis\n  } else throw e;\n}","preventionTips":["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."],"tags":["mongodb","server-version","unexpected-response","buildinfo"],"backgroundTag":"unexpected-server-response","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}