{"record":{"id":"1184ca8507f8a7a9","repo":"t8y2/dbx","slug":"each-mongodb-aggregate-pipeline-stage-must-be-an-o","errorCode":null,"errorMessage":"Each MongoDB aggregate pipeline stage must be an object","messagePattern":"Each MongoDB aggregate pipeline stage must be an object","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":530,"sourceCode":"            documents.subList(maxRows, documents.size()).clear();\n            extendedDocuments.subList(maxRows, extendedDocuments.size()).clear();\n        }\n        return documentQueryResultWithExtended(documents, extendedDocuments, total);\n    }\n\n    static List<Document> aggregatePipeline(JsonObject params) {\n        String source = stringOrNull(params, \"pipeline\");\n        if (source == null || source.isBlank()) {\n            throw new IllegalArgumentException(\"MongoDB aggregate pipeline is required\");\n        }\n        JsonElement parsed = JsonParser.parseString(source);\n        if (!parsed.isJsonArray()) {\n            throw new IllegalArgumentException(\"MongoDB aggregate pipeline must be a JSON array\");\n        }\n        List<Document> pipeline = new ArrayList<>();\n        for (JsonElement stage : parsed.getAsJsonArray()) {\n            if (!stage.isJsonObject()) {\n                throw new IllegalArgumentException(\"Each MongoDB aggregate pipeline stage must be an object\");\n            }\n            pipeline.add(Document.parse(stage.toString()));\n        }\n        return pipeline;\n    }\n\n    static Document aggregateOptions(JsonObject params) {\n        Document options = documentOrNull(params, \"options\");\n        return options == null ? new Document() : options;\n    }\n\n    static boolean aggregateExplain(Document options) {\n        Object explain = options.get(\"explain\");\n        if (explain == null) {\n            return false;\n        }\n        if (!(explain instanceof Boolean)) {\n            throw new IllegalArgumentException(\"MongoDB aggregate option explain must be a boolean\");","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L512-L548","documentation":"Thrown by MongoAgent.aggregatePipeline while iterating the parsed pipeline array when an element is not a JSON object. Every aggregation stage must be a document like {\"$match\": ...}; a bare string, number, or nested array at stage position triggers this rejection.","triggerScenarios":"Thrown at agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java:530 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make each array element a single-key stage object, e.g. {\"$sort\": {\"_id\": -1}}","Check for trailing commas or misplaced brackets that turn a stage into a non-object JSON value","Re-test the pipeline in mongosh before submitting it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}