Skip to content

SortArray does not support sorting simple array types (integer/string) #4929

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

Open
nathanukey opened this issue Mar 18, 2025 · 3 comments
Open
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement

Comments

@nathanukey
Copy link

nathanukey commented Mar 18, 2025

Referring to https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/

sorting of simple e.g. int array should be possible:

"$sortArray":
{
    "input": [ 1, 4, 1, 6, 12, 5 ],
    "sortBy": 1
}

however ArrayOperators.SortArray.by only accepts type Sort, which seems to always require a property. Not clear if any way to set a simple ASC/DESC order to sort by.

Seems simple feature that has been missed off, or if possible missed of documentation on how to achieve?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 18, 2025
@mp911de mp911de added status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 24, 2025
@mp911de
Copy link
Member

mp911de commented Mar 24, 2025

Thanks for reaching out. Care to submit a pull request?

@nathanukey
Copy link
Author

Tried to create PR as requested: 5258a80

ranzyblessings added a commit to ranzyblessings/spring-data-mongodb that referenced this issue Apr 10, 2025
…ray (Fixes spring-projects#4929)

- Added methods `byValueAscending()` and `byValueDescending()` to the SortArray class
  to support sorting simple array types (e.g., integers, strings) in ascending and descending order.
- Updated tests to verify the correct functionality of sorting arrays by value.
- Refactored SortArray to handle sorting of simple types without requiring a property for sorting.

For more details, refer to: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/

Signed-off-by: Ranzy Blessings <ranzyblessings.inbox@gmail.com>
@ranzyblessings
Copy link

Hello team,

I’ve addressed the issue with sorting simple arrays (integers/strings) in PR #4943 . The fix includes the addition of the byValueAscending() and byValueDescending() methods, along with updated tests to ensure correct functionality.

Please don’t hesitate to reach out if any further modifications or adjustments are needed. I’m happy to make any necessary changes.

Best regards,
Ranzy Blessings

ranzyblessings added a commit to ranzyblessings/spring-data-mongodb that referenced this issue Apr 11, 2025
…h SortArray (Fixes spring-projects#4929) to cleanup excessive formatting"

This reverts commit 0422055.
ranzyblessings added a commit to ranzyblessings/spring-data-mongodb that referenced this issue Apr 11, 2025
…ixes spring-projects#4929) spring-projects#4943 - Removed unnecessary whitespaces

- Added methods byValueAscending() and byValueDescending() to the SortArray class
to support sorting simple array types (e.g., integers, strings) in ascending and descending order.
- Updated tests to verify the correct functionality of sorting arrays by value.
- Refactored SortArray to handle sorting of simple types without requiring a property for sorting.
- Removed unnecessary whitespaces and formatting changes to ensure clean, readable code.

For more details, refer to: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/

Signed-off-by: Ranzy Blessings <ranzyblessings.inbox@gmail.com>
ranzyblessings added a commit to ranzyblessings/spring-data-mongodb that referenced this issue Apr 11, 2025
…h SortArray (Fixes spring-projects#4929) to cleanup excessive formatting"

This reverts commit 0422055.

Signed-off-by: Ranzy Blessings <ranzyblessings.inbox@gmail.com>
ranzyblessings added a commit to ranzyblessings/spring-data-mongodb that referenced this issue Apr 11, 2025
…ixes spring-projects#4929) spring-projects#4943 - Removed unnecessary whitespaces

- Added methods byValueAscending() and byValueDescending() to the SortArray class
to support sorting simple array types (e.g., integers, strings) in ascending and descending order.
- Updated tests to verify the correct functionality of sorting arrays by value.
- Refactored SortArray to handle sorting of simple types without requiring a property for sorting.
- Removed unnecessary whitespaces and formatting changes to ensure clean, readable code.

For more details, refer to: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/

Signed-off-by: Ranzy Blessings <ranzyblessings.inbox@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants