{"record":{"id":"889dc903713ba60f","repo":"t8y2/dbx","slug":"dropindex-requires-a-string-index-name-or-json-doc","errorCode":null,"errorMessage":"dropIndex requires a string index name or JSON document","messagePattern":"dropIndex requires a string index name or JSON document","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":1367,"sourceCode":"        // options accepted by createIndexes on every supported server.\n        definition.remove(\"v\");\n        definition.remove(\"ns\");\n        definition.remove(\"buildUUID\");\n        definition.remove(\"ready\");\n        return definition;\n    }\n\n    private static Object dropDatabase(JsonObject params) {\n        MongoClient c = requireClient();\n        String database = params.get(\"database\").getAsString();\n        c.getDatabase(database).drop();\n        return Collections.singletonMap(\"ok\", true);\n    }\n\n    static Object parseDropIndexesValue(String indexesJson, boolean single) {\n        if (indexesJson == null || indexesJson.isBlank()) {\n            if (single) {\n                throw new IllegalArgumentException(\"dropIndex requires a string index name or JSON document\");\n            }\n            return \"*\";\n        }\n\n        JsonElement value = JsonParser.parseString(indexesJson);\n        if (value.isJsonPrimitive() && value.getAsJsonPrimitive().isString()) {\n            String name = value.getAsString();\n            if (name.isBlank()) {\n                throw new IllegalArgumentException(\"Index name is required\");\n            }\n            if (single && \"*\".equals(name)) {\n                throw new IllegalArgumentException(\"dropIndex does not accept \\\"*\\\"; use dropIndexes() or dropIndexes(\\\"*\\\") instead\");\n            }\n            if (DEFAULT_ID_INDEX_NAME.equals(name)) {\n                throw new IllegalArgumentException(\"The default MongoDB _id_ index cannot be dropped\");\n            }\n            return name;\n        }","sourceCodeStart":1349,"sourceCodeEnd":1385,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L1349-L1385","documentation":"parseDropIndexesValue validates the indexesJson argument for the dropIndex action. When the argument is missing, null, or blank and single=true (dropIndex mode), the agent throws because a dropIndex call must name exactly one index to drop.","triggerScenarios":"Invoking dropIndex without the indexes parameter, with an empty string, or with whitespace only; calling dropIndex while relying on the batch default \"*\" which is only allowed for dropIndexes.","commonSituations":"Omitting the JSON body field in a tool call; wiring a template variable that resolves to \"\"; copying a dropIndexes() call and renaming only the action name to dropIndex.","solutions":["Pass a non-blank index name string, e.g. \"age_1\"","Pass a JSON key-pattern document like {\"age\": 1}","If you intend to drop all indexes, call dropIndexes (with \"*\") instead"],"exampleFix":"// before\nagent.execute(\"dropIndex\", Map.of(\"database\", \"shop\", \"collection\", \"orders\")); // no indexes\n// after\nagent.execute(\"dropIndex\", Map.of(\n    \"database\", \"shop\",\n    \"collection\", \"orders\",\n    \"indexes\", \"age_1\"\n));","handlingStrategy":"validation","validationCode":"if (indexesJson == null || indexesJson.isBlank()) {\n    throw new IllegalArgumentException(\"dropIndex needs a non-blank index name or JSON document\");\n}","typeGuard":"boolean hasDropIndexTarget(String indexesJson) {\n    return indexesJson != null && !indexesJson.isBlank();\n}","tryCatchPattern":"try {\n    agent.execute(\"dropIndex\", params);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"requires a string index name\")) {\n        throw new IllegalStateException(\"indexes parameter is mandatory for dropIndex\", e);\n    } else { throw e; }\n}","preventionTips":["Always pass the indexes parameter explicitly for dropIndex","Use dropIndexes for wildcard/batch operations","Validate template/config variables are non-empty before substitution"],"tags":["validation","mongodb","arguments","indexes"],"backgroundTag":"missing-required-argument","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"}