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

"the $sort key specification must be an object" #63

Closed
trycoon opened this issue Jul 22, 2024 · 4 comments
Closed

"the $sort key specification must be an object" #63

trycoon opened this issue Jul 22, 2024 · 4 comments
Labels
fixed This issue is solved/fixed.

Comments

@trycoon
Copy link

trycoon commented Jul 22, 2024

I'm running "mongoose: 8.5.1" and "mongoose-aggregate-paginate-v2: 1.0.7" without any problems.
When I upgrade to "mongoose-aggregate-paginate-v2: 1.1.1" I get the following error: "the $sort key specification must be an object".

My function looks like this:

  async query({
    limit,
    offset,
    sort,
    name,
  }) {
    // https://github.com/aravindnc/mongoose-aggregate-paginate-v2#usage
    const options = {
      offset,
      limit,
      sort,
      customLabels: {
        docs: 'exercises',
      },
    };

    const myAggregate = this.#exercise.aggregate([{
      $match: { name: new RegExp(String.raw`^${name || ''}.*`, 'i') },
    }]);
    const result = await this.#exercise.aggregatePaginate(myAggregate, options);
    // Stupid "lean=true" and "leanWithId=true" does not work, so we have to extract "id" ourself.
    result.exercises = result.exercises.map((e) => {
      // eslint-disable-next-line no-underscore-dangle
      e.id = String(e._id);
      return e;
    });
    return result;
  }

I use it like this:

query({
  limit: 20,
  offset: 0,
  sort: "name",
})

Somehow the sort-parameter is broken in the new version!

@aravindnc
Copy link
Owner

@Akalanka47000 Seems your Prepaginate feature update is causing this issue. Can you take a look.

Akalanka47000 added a commit to sliit-foss/mongoose-aggregate-paginate-v2 that referenced this issue Jul 23, 2024
@Akalanka47000
Copy link
Contributor

Fixed @aravindnc, apologies for the trouble

aravindnc added a commit that referenced this issue Jul 23, 2024
Fixes the sorting issue (#63) and failing test cases
@aravindnc
Copy link
Owner

@Akalanka47000 Awesome. I will publish updated package today.
@trycoon

@aravindnc aravindnc added the fixed This issue is solved/fixed. label Jul 23, 2024
@trycoon
Copy link
Author

trycoon commented Jul 23, 2024

Thanks, both of you! Its working as expected with the latest version. I'm closing the issue.

@trycoon trycoon closed this as completed Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed This issue is solved/fixed.
Projects
None yet
Development

No branches or pull requests

3 participants