{"record":{"id":"f08412f9e37fd6bb","repo":"t8y2/dbx","slug":"mongodb-aggregate-pipeline-must-be-a-json-array","errorCode":null,"errorMessage":"MongoDB aggregate pipeline must be a JSON array","messagePattern":"MongoDB aggregate pipeline must be a JSON array","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":525,"sourceCode":"                extendedDocuments.add(bsonToExtendedJson(document));\n            }\n        }\n        long total = documents.size();\n        if (documents.size() > maxRows) {\n            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\");","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L507-L543","documentation":"Thrown by MongoAgent.aggregatePipeline after successfully JSON-parsing the 'pipeline' parameter when the top-level parsed element is not a JSON array (e.g. an object or scalar). MongoDB aggregation pipelines must be arrays of stage documents, so the shape is rejected.","triggerScenarios":"Thrown at agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java:525 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wrap stages in square brackets: pipeline must be \"[ {stage1}, {stage2} ]\"","Remove any stray object or string wrapper around the stage array","Validate the value with a JSON linter before sending"],"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-14T00:17:10.932Z"}