...
BugZero found this defect 19 days ago.
A simple use case for $fill is to replace nulls with a constant value. Imagine a collection with a numeric field "amount" which may be null or missing. We can use $fill to replace null or missing with 0: MongoDB Enterprise > db.c.find() { "_id" : 1, "amount" : 4 } { "_id" : 2, "amount" : 0 } { "_id" : 3, "amount" : null } { "_id" : 4 } MongoDB Enterprise > db.c.aggregate([{$fill: {output: {amount: {value: 0}}}}]) { "_id" : 1, "amount" : 4 } { "_id" : 2, "amount" : 0 } { "_id" : 3, "amount" : 0 } { "_id" : 4, "amount" : 0 } Partitioning and ordering doesn't have any effect for this simple use case of filling nulls (as opposed to something like filling via linear interpolation). However, if we specify an invalid "partitionBy" expression, the system does not raise an error: MongoDB Enterprise > db.c.aggregate([{$fill: {partitionBy: {$bogus: 1}, output: {amount: {value: 0}}}}]) { "_id" : 1, "amount" : 4 } { "_id" : 2, "amount" : 0 } { "_id" : 3, "amount" : 0 } { "_id" : 4, "amount" : 0 } This happens because the implementation rewrites $fill into an $addFields without ever attempting to parse the "partitionBy" expression. Arguably the entire query should always be parsed in order to catch simple syntactic errors, even if the expression with the invalid syntax can be optimized away as happens in this case.