Skip to content

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

New issue

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

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

Already on GitHub? # to your account

Closed
Saljack opened this issue Dec 18, 2024 · 1 comment
Closed
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.

@mp911de mp911de added this to the 4.5 M1 (2025.0.0) milestone Jan 7, 2025
@mp911de mp911de closed this as completed in d870026 Jan 7, 2025
mp911de added a commit that referenced this issue Jan 7, 2025
Refine naming. Reformat code.

Original pull request: #4858
See #4857
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants