{"record":{"id":"1d5bb96e1c6cac1a","repo":"t8y2/dbx","slug":"dropindex-only-accepts-a-string-index-name-or-json-1d5bb9","errorCode":null,"errorMessage":"dropIndex only accepts a string index name or JSON document","messagePattern":"dropIndex only accepts 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":1417,"sourceCode":"                throw new IllegalArgumentException(\"dropIndex only accepts a string index name or JSON document; arrays are not supported\");\n            }\n            List<String> names = new ArrayList<>();\n            value.getAsJsonArray().forEach(item -> {\n                if (!item.isJsonPrimitive() || !item.getAsJsonPrimitive().isString() || item.getAsString().isBlank()) {\n                    throw new IllegalArgumentException(\"dropIndexes only accepts arrays of string index names\");\n                }\n                names.add(item.getAsString());\n            });\n            if (names.isEmpty()) {\n                throw new IllegalArgumentException(\"dropIndexes only accepts non-empty string arrays\");\n            }\n            if (names.contains(DEFAULT_ID_INDEX_NAME)) {\n                throw new IllegalArgumentException(\"The default MongoDB _id_ index cannot be dropped\");\n            }\n            return names;\n        }\n        if (single) {\n            throw new IllegalArgumentException(\"dropIndex only accepts a string index name or JSON document\");\n        }\n        throw new IllegalArgumentException(\"dropIndexes only accepts a string index name, JSON document, or string array\");\n    }\n\n    private static boolean isDefaultIdIndexSpecification(Document specification) {\n        if (specification.size() != 1 || !specification.containsKey(\"_id\")) {\n            return false;\n        }\n        Object direction = specification.get(\"_id\");\n        if (direction instanceof Number number) {\n            return number.doubleValue() == 1.0;\n        }\n        // Document.parse turns Extended JSON $numberDecimal values into\n        // Decimal128, which does not implement Number in the legacy driver.\n        return direction instanceof Decimal128 decimal\n            && decimal.bigDecimalValue().compareTo(BigDecimal.ONE) == 0;\n    }\n","sourceCodeStart":1399,"sourceCodeEnd":1435,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L1399-L1435","documentation":"dropIndex expects a string index name or a JSON-object index-key specification. This error means the argument parsed as neither — e.g. a number, boolean, or null. It is the fall-through rejection after string, object, and array cases were all exhausted in the single (dropIndex) path.","triggerScenarios":"Calling dropIndex with a non-string/non-object JSON argument such as '123', 'true', or 'null'; passing a mis-serialized value where quotes were lost so the name became an invalid JSON token; blank index names are caught earlier with a separate message, so this is the malformed-type case.","commonSituations":"String interpolation bugs where the index name variable is null and 'null' is passed; tooling that JSON-encodes a non-string variable; API consumers reading the index name from config and getting a wrong type (number instead of string).","solutions":["Pass the index name as a JSON string: dropIndex(\"my_index_name\")","Or pass a key specification object: dropIndex(\"{\\\"field\\\": 1}\")","Log/print the exact argument being passed and confirm it is a quoted JSON string or object"],"exampleFix":"// before\nagent.dropIndex(String.valueOf(indexId)); // e.g. \"123\"\n// after\nagent.dropIndex(\"email_1_age_-1\"); // a string index name","handlingStrategy":"type-guard","validationCode":"if (typeof indexName !== 'string' || indexName.trim() === '') {\n  throw new Error('dropIndex requires a non-empty string index name, got: ' + typeof indexName);\n}","typeGuard":"const isIndexName = (v) => typeof v === 'string' && v.trim() !== '';","tryCatchPattern":"try {\n  agent.dropIndex(String(arg));\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"dropIndex only accepts a string index name or JSON document\")) {\n    log.error('Bad dropIndex argument type', { arg });\n  } else throw e;\n}","preventionTips":["Pass index names as quoted JSON strings, never bare literals","Check the source variable's type (config values can come back as numbers)","Use listIndexes to copy exact names"],"tags":["mongodb","argument-validation","dropindex","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}