{"record":{"id":"ab4e5b23646a7c84","repo":"t8y2/dbx","slug":"each-arrayfilters-entry-must-be-an-object","errorCode":null,"errorMessage":"Each arrayFilters entry must be an object","messagePattern":"Each arrayFilters entry must be an object","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":1626,"sourceCode":"            return result;\n        }\n        Document options = Document.parse(optionsJson);\n        for (String key : options.keySet()) {\n            if (!\"arrayFilters\".equals(key)) {\n                throw new IllegalArgumentException(\"Unsupported update option: \" + key);\n            }\n        }\n        Object rawFilters = options.get(\"arrayFilters\");\n        if (rawFilters == null) {\n            return result;\n        }\n        if (!(rawFilters instanceof List<?>)) {\n            throw new IllegalArgumentException(\"arrayFilters must be an array\");\n        }\n        List<Document> filters = new ArrayList<>();\n        for (Object filter : (List<?>) rawFilters) {\n            if (!(filter instanceof Document)) {\n                throw new IllegalArgumentException(\"Each arrayFilters entry must be an object\");\n            }\n            filters.add((Document) filter);\n        }\n        return result.arrayFilters(filters);\n    }\n\n    static Document documentForWrite(String docJson) {\n        Document doc = Document.parse(docJson);\n        convertMongoShellDates(doc);\n        return doc;\n    }\n\n    private static boolean isUpdatePipelineJson(String updateJson) {\n        return updateJson.trim().startsWith(\"[\");\n    }\n\n    static List<Document> updatePipelineForWrite(String updateJson) {\n        JsonElement parsed = JsonParser.parseString(updateJson);","sourceCodeStart":1608,"sourceCodeEnd":1644,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L1608-L1644","documentation":"Each entry inside the `arrayFilters` array must itself be an object (a BSON Document of filter conditions for the `$[<identifier>]` positional operator). MongoAgent iterates the array and rejects any scalar, string, or array element with this IllegalArgumentException because the Java driver requires List<Document>.","triggerScenarios":"Calling an update with `\"arrayFilters\": [\"g.level >= 90\"]` or `[\"g\"]` — array elements are strings/numbers rather than filter documents like `[{\"g.level\": {\"$gte\": 90}}]`.","commonSituations":"Typing filter expressions as strings instead of documents; copy-pasting shell syntax into JSON; generating arrayFilters programmatically with wrong element type; a stray null element in the array.","solutions":["Make every arrayFilters element a JSON object: `[{\"g.level\": {\"$gte\": 90}}]`.","Quote field paths as keys, not expressions: use `{\"g.score\": {\"$exists\": true}}`, not `\"g.score exists\"`.","Check for null or empty string entries if arrayFilters is built dynamically.","Validate each element serializes as `{...}` before sending the request."],"exampleFix":"// before\n\"arrayFilters\": [\"g.level: {$gte: 90}\"]\n// after\n\"arrayFilters\": [{\"g.level\": {\"$gte\": 90}}]","handlingStrategy":"validation","validationCode":"// Java: every element must be a Document/map\nObject af = options.get(\"arrayFilters\");\nif (af instanceof List<?> l) {\n    for (Object e : l) {\n        if (!(e instanceof java.util.Map))\n            throw new IllegalArgumentException(\"Each arrayFilters entry must be an object\");\n    }\n}","typeGuard":"static boolean isValidArrayFilters(Object v) { return v instanceof List<?> l && l.stream().allMatch(x -> x instanceof java.util.Map<?, ?>); }","tryCatchPattern":"try { agent.updateOne(filter, update, options); }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"arrayFilters entry must be an object\")) {\n    // convert string entries into {path: value} documents and retry\n  } else throw e;\n}","preventionTips":["Write arrayFilters entries as {\"identifier.field\": condition} documents","Never embed filter expressions as raw strings","Sanitize dynamically built arrays to drop nulls before sending"],"tags":["mongodb","validation","argument-type","update"],"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-14T05:17:10.506Z"}