-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: 8.2.4, 7.0.31, 8.2.6, 8.2.12
-
Component/s: None
-
None
-
Query Execution
-
ALL
-
-
None
-
None
-
None
-
None
-
None
-
None
-
None
onError is meant to replace a failed conversion with the value given instead of failing the pipeline. Converting a date outside the supported year range to a string returns error 18537 even with onError set, so the pipeline fails and the value is never used.
onError does work for other conversion failures on the same server, so it is not being ignored outright. This returns caught as expected.
db.d.aggregate([{$project: {_id: 0, s: {$convert: {
input: "not a number", to: "int", onError: "caught"
}}}}]);
Dropping onError from the failing pipeline gives the same error 18537, which is correct on its own. A date inside the range converts normally, so only the onError handling is affected.
The same thing happens with a constant instead of a field reference, though the message text differs slightly between the two.
Expected
A single document with s set to caught.
Actual
Error 18537, and no documents returned.
The date here is built with $toDate from a millisecond value because drivers cannot represent years outside 1 to 9999.