{"record":{"id":"91c4289a12292d6e","repo":"t8y2/dbx","slug":"dropindex-only-accepts-a-string-index-name-or-json","errorCode":null,"errorMessage":"dropIndex only accepts a string index name or JSON document; arrays are not supported","messagePattern":"dropIndex only accepts a string index name or JSON document; arrays are not supported","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":1399,"sourceCode":"            if (DEFAULT_ID_INDEX_NAME.equals(name)) {\n                throw new IllegalArgumentException(\"The default MongoDB _id_ index cannot be dropped\");\n            }\n            return name;\n        }\n        if (value.isJsonObject()) {\n            JsonObject object = value.getAsJsonObject();\n            if (object.size() == 0) {\n                throw new IllegalArgumentException(\"Index specification is required\");\n            }\n            Document specification = Document.parse(indexesJson);\n            if (isDefaultIdIndexSpecification(specification)) {\n                throw new IllegalArgumentException(\"The default MongoDB _id_ index cannot be dropped\");\n            }\n            return specification;\n        }\n        if (value.isJsonArray()) {\n            if (single) {\n                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\");","sourceCodeStart":1381,"sourceCodeEnd":1417,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L1381-L1417","documentation":"This error comes from the index-specification parser shared by dropIndex/dropIndexes in MongoAgent. When the 'single' flag is set (dropIndex), the parsed JSON argument must be either a string index name or a JSON-object key/direction specification. An array was passed instead, which dropIndex does not accept; dropIndexes is the multi-name API that accepts arrays.","triggerScenarios":"Calling dropIndex with a JSON array argument such as '[[\"idx_a\",\"idx_b\"]]' or '[\"idx_a\"]', instead of a string name ('idx_a') or an object ('{\"field\": 1}'). The parser detects a JSON array value and immediately rejects it because arrays are only valid for dropIndexes.","commonSituations":"Developers reusing code written for dropIndexes (which takes arrays of names) and calling dropIndex with the same array; scripting layers that build arguments dynamically and pass a list even when only one index is targeted; confusion after a driver upgrade that tightened argument validation.","solutions":["Pass a single index name string to dropIndex, e.g. dropIndex(\"users_email_idx\")","If you have multiple indexes to drop, call dropIndexes with the array instead of dropIndex","If the index is described by a key/direction spec, pass a JSON object like {\"email\": 1} rather than an array"],"exampleFix":"// before\nagent.dropIndex(\"[\\\"email_idx\\\", \\\"name_idx\\\"]\");\n// after\nagent.dropIndex(\"email_idx\");\n// or for multiple:\nagent.dropIndexes(\"[\\\"email_idx\\\", \\\"name_idx\\\"]\");","handlingStrategy":"validation","validationCode":"// JS-ish caller-side check before calling dropIndex\nfunction assertDropIndexArg(arg) {\n  if (typeof arg === 'string' && arg.trim() !== '') return;      // name OK\n  if (typeof arg === 'object' && arg !== null && !Array.isArray(arg)\n      && Object.keys(arg).length > 0) return;                     // key spec OK\n  throw new Error('dropIndex requires a non-empty string name or a JSON object spec, not an array');\n}","typeGuard":"function isDropIndexSpec(v) {\n  return (typeof v === 'string' && v.trim() !== '') ||\n         (v !== null && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length > 0);\n}","tryCatchPattern":"try {\n  agent.dropIndex(arg);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"arrays are not supported\")) {\n    agent.dropIndexes(arrayJson); // route arrays to dropIndexes\n  } else throw e;\n}","preventionTips":["Use dropIndex only for one index; reserve dropIndexes for lists","Keep a thin wrapper function that dispatches arrays to dropIndexes automatically","Document index names as strings, never arrays, in internal tooling"],"tags":["mongodb","argument-validation","dropindex"],"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"}