{"record":{"id":"7922873f6122b376","repo":"t8y2/dbx","slug":"invalid-collation-option-key-expected-a-boolea","errorCode":null,"errorMessage":"Invalid collation option ${key}: expected a boolean","messagePattern":"Invalid collation option (.+?): expected a boolean","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java","lineNumber":865,"sourceCode":"        }\n        if (document.containsKey(\"maxVariable\")) {\n            builder.collationMaxVariable(CollationMaxVariable.fromString(collationString(document, \"maxVariable\")));\n        }\n        if (document.containsKey(\"normalization\")) {\n            builder.normalization(collationBoolean(document, \"normalization\"));\n        }\n        if (document.containsKey(\"backwards\")) {\n            builder.backwards(collationBoolean(document, \"backwards\"));\n        }\n        return builder.build();\n    }\n\n    private static boolean collationBoolean(Document document, String key) {\n        Object value = document.get(key);\n        if (value instanceof Boolean booleanValue) {\n            return booleanValue;\n        }\n        throw new IllegalArgumentException(\"Invalid collation option \" + key + \": expected a boolean\");\n    }\n\n    private static String collationString(Document document, String key) {\n        Object value = document.get(key);\n        if (value instanceof String stringValue) {\n            return stringValue;\n        }\n        throw new IllegalArgumentException(\"Invalid collation option \" + key + \": expected a string\");\n    }\n\n    static CollectionTotal collectionTotal(MongoCollection<Document> collection, Document filter) {\n        return collectionTotal(collection, filter, null);\n    }\n\n    static CollectionTotal collectionTotal(MongoCollection<Document> collection, Document filter, Collation collation) {\n        if (filter.isEmpty()) {\n            return new CollectionTotal(collection.estimatedDocumentCount(), false);\n        }","sourceCodeStart":847,"sourceCodeEnd":883,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java#L847-L883","documentation":"Boolean collation options (caseLevel, caseFirst-related toggles like backwards, normalization, numericOrdering) are read via collationBoolean, which requires the value to be an actual Boolean. Any other type throws this error naming the offending key.","triggerScenarios":"Passing e.g. {\"caseLevel\":\"true\"}, {\"numericOrdering\":1}, or {\"backwards\":null} in a collation document.","commonSituations":"JSON configs where booleans were serialized as strings; 0/1 integer flags from other systems; templating that stringifies values.","solutions":["Pass a real boolean (true/false), not a string or number","Convert \"true\"/\"false\" strings with Boolean.parseBoolean before calling","Convert 1/0 numeric flags with (value != 0)","Remove the key to use the default (false for these flags)"],"exampleFix":"// before\n{\"collation\":{\"locale\":\"en\",\"caseLevel\":\"true\"}}\n// after\n{\"collation\":{\"locale\":\"en\",\"caseLevel\":true}}","handlingStrategy":"type-guard","validationCode":"const BOOL_KEYS = ['caseLevel','numericOrdering','normalization','backwards'];\nfor (const k of BOOL_KEYS) {\n  if (collation[k] != null && typeof collation[k] !== 'boolean') {\n    throw new Error('collation.' + k + ' must be a boolean');\n  }\n}","typeGuard":"function isBoolean(v) {\n  return typeof v === 'boolean';\n}","tryCatchPattern":"try {\n  result = agent.findOne(params);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().includes('expected a boolean')) {\n    const key = e.getMessage().match(/option (\\w+):/)[1];\n    params.collation[key] = params.collation[key] === 'true' || params.collation[key] === 1;\n    result = agent.findOne(params);\n  } else throw e;\n}","preventionTips":["Ensure JSON serialization preserves booleans (no \"true\" strings)","Convert 0/1 flags to booleans at ingestion","Coerce query-string booleans with strict parsing (only 'true'/'false')","Type-check collation configs before sending"],"tags":["mongodb","collation","boolean","type-error"],"backgroundTag":"invalid-option-value","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"}