$slice does not support AggregationExpression for offset and itemCount
Saljack opened this issue · 1 comments
Saljack commented
I try to write aggregation with $slice
and split an array and use another expression for itemCount. But current ArrayOperators.Slice
supports only int for offset and itemCount. These values can be also expression see https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/
For example I would like to slice an array myArray
and remove the last item from this array:
"arrayWithoutLastItem": {
"$slice": [
"$myArray",
{ "$subtract": [ {"$size": "$myArray"}, 1]}
]
}
I would like to write it like this:
ArrayOperators.Slice.sliceArrayOf("myArray")
.itemCount(
Subtract.valueOf(
ArrayOperators.Size.lengthOfArray("myArray")
).subtract(1)
)
christophstrobl commented
Thanks for the heads up @Saljack! Yes, that seems to be missing in Slice
.