t8y2/dbx · error · java.lang.IllegalArgumentException

dropIndex does not accept "*"; use dropIndexes() or dropInde

Error message

dropIndex does not accept "*"; use dropIndexes() or dropIndexes("*") instead

What it means

The wildcard "*" means 'drop all indexes' and is supported only by dropIndexes (single=false). dropIndex intentionally rejects "*" to prevent accidental mass index deletion through the single-index API, directing users to the batch action.

Source

Thrown at agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java:1379

        return Collections.singletonMap("ok", true);
    }

    static Object parseDropIndexesValue(String indexesJson, boolean single) {
        if (indexesJson == null || indexesJson.isBlank()) {
            if (single) {
                throw new IllegalArgumentException("dropIndex requires a string index name or JSON document");
            }
            return "*";
        }

        JsonElement value = JsonParser.parseString(indexesJson);
        if (value.isJsonPrimitive() && value.getAsJsonPrimitive().isString()) {
            String name = value.getAsString();
            if (name.isBlank()) {
                throw new IllegalArgumentException("Index name is required");
            }
            if (single && "*".equals(name)) {
                throw new IllegalArgumentException("dropIndex does not accept \"*\"; use dropIndexes() or dropIndexes(\"*\") instead");
            }
            if (DEFAULT_ID_INDEX_NAME.equals(name)) {
                throw new IllegalArgumentException("The default MongoDB _id_ index cannot be dropped");
            }
            return name;
        }
        if (value.isJsonObject()) {
            JsonObject object = value.getAsJsonObject();
            if (object.size() == 0) {
                throw new IllegalArgumentException("Index specification is required");
            }
            Document specification = Document.parse(indexesJson);
            if (isDefaultIdIndexSpecification(specification)) {
                throw new IllegalArgumentException("The default MongoDB _id_ index cannot be dropped");
            }
            return specification;
        }
        if (value.isJsonArray()) {

View on GitHub (pinned to c0390bff16)

Solutions

  1. Use dropIndexes with "*" to drop all secondary indexes
  2. Or call dropIndex once per specific index name you want removed
  3. Remember the _id_ index can never be dropped either way

Example fix

// before
agent.execute("dropIndex", Map.of("indexes", "*"));
// after
agent.execute("dropIndexes", Map.of("indexes", "*")); // batch drop of all secondary indexes
Defensive patterns

Strategy: validation

Validate before calling

if ("*".equals(indexName) || "\"*\"".equals(indexesJson)) {
    // route to batch API instead
    agent.execute("dropIndexes", Map.of("indexes", "*"));
    return;
}

Type guard

boolean isWildcardIndex(String name) {
    return "*".equals(name);
}

Try / catch

try {
    agent.execute("dropIndex", params);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("does not accept")) {
        agent.execute("dropIndexes", Map.of("indexes", "*"));
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling dropIndex with indexes="*" (or JSON string "\"*\"") intending to clear all indexes.

Common situations: Migrating a schema and wanting a clean index slate; copying dropIndexes("*") examples but invoking the wrong action name.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/43ae392912299818. Report an issue: GitHub.