Skip to content

GET /v1/holders ignores sort_order query parameter — always returns ascending #2012

@gandalf-at-lerian

Description

@gandalf-at-lerian

Description

The GET /v1/holders?sort_order=desc endpoint always returns results in ascending order regardless of the sort_order query parameter value.

Root Cause

In components/crm/internal/adapters/mongodb/holder/holder_query.mongodb.go, the FindAll method hardcodes the sort direction:

opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(bson.D{{Key: "_id", Value: 1}})

The sort is always _id: 1 (ascending). The query.SortOrder value is recorded in span attributes for tracing but is never applied to the MongoDB query options.

Expected Behavior

  • sort_order=asc → results sorted by _id: 1 (ascending)
  • sort_order=desc → results sorted by _id: -1 (descending)

Suggested Fix

sortDirection := 1
if strings.EqualFold(query.SortOrder, "desc") {
    sortDirection = -1
}
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(bson.D{{Key: "_id", Value: sortDirection}})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions