Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Moved mongo id translation to mongo file
Browse files Browse the repository at this point in the history
  • Loading branch information
icellan committed Apr 21, 2022
1 parent 62c7625 commit eab9f7c
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 0 additions & 3 deletions datastore/models.go
Original file line number Diff line number Diff line change
@@ -215,9 +215,6 @@ func (c *Client) GetModels(
// init a new empty object for the default queryParams
queryParams = &QueryParams{}
}
if queryParams.OrderByField == "id" {
queryParams.OrderByField = "_id" // use Mongo _id instead of default id field
}
// Set default page size
if queryParams.Page > 0 && queryParams.PageSize < 1 {
queryParams.PageSize = defaultPageSize
3 changes: 3 additions & 0 deletions datastore/mongodb.go
Original file line number Diff line number Diff line change
@@ -203,6 +203,9 @@ func (c *Client) getWithMongo(
opts = append(opts, options.Find().SetLimit(int64(queryParams.PageSize)).SetSkip(int64(queryParams.PageSize*(queryParams.Page-1))))
}

if queryParams.OrderByField == "id" {
queryParams.OrderByField = "_id" // use Mongo _id instead of default id field
}
if queryParams.OrderByField != "" {
sortOrder := 1
if queryParams.SortDirection == "desc" {

0 comments on commit eab9f7c

Please sign in to comment.