Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$slice does not support AggregationExpression for offset and itemCount #4857

Open
Saljack opened this issue Dec 18, 2024 · 1 comment · May be fixed by #4858
Open

$slice does not support AggregationExpression for offset and itemCount #4857

Saljack opened this issue Dec 18, 2024 · 1 comment · May be fixed by #4858
Assignees
Labels
type: enhancement A general enhancement

Comments

@Saljack
Copy link

Saljack commented Dec 18, 2024

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)
   )
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 18, 2024
@christophstrobl christophstrobl self-assigned this Dec 18, 2024
@christophstrobl christophstrobl added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 18, 2024
@christophstrobl
Copy link
Member

Thanks for the heads up @Saljack! Yes, that seems to be missing in Slice.

@christophstrobl christophstrobl linked a pull request Dec 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants