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

mongoosePlugin throws "collatedQuery.sort" in paginate method #315

Open
edneyreis opened this issue Jan 27, 2022 · 0 comments
Open

mongoosePlugin throws "collatedQuery.sort" in paginate method #315

edneyreis opened this issue Jan 27, 2022 · 0 comments

Comments

@edneyreis
Copy link

Environment:

Node: v14.18.2
Npm: 6.14.15
Mongoose: 5.13.13
Mongo: 3.7.3
Mongo-cursor-pagination: 7.6.1

Steps to reproduce:

const mongoose = require('mongoose');
const MongoPaging = require('mongo-cursor-pagination');

const DummySchema = mongoose.Schema(
  {
    user: String,
  },
  {
    timestamps: { createdAt: 'date' },
  },
);

// this will add paginate function.
DummySchema.plugin(MongoPaging.mongoosePlugin);

const Dummy = mongoose.model('Dummy', DummySchema);

let paginateParams = {
  limit: 10,
  sort: '-date',
};

Dummy.paginate(paginateParams)
  .then(result => {
    console.log(result);
  })
  .catch(err => {
    console.log(err);
  });

Proposed solution:

mongo-cursor-pagination/src/find.js

change const query = collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields);
to: const query = await collection[findMethod]({ $and: [cursorQuery, params.query] }, params.fields);

@edneyreis edneyreis changed the title mongoosePlugin paginate throws "collatedQuery.sort" mongoosePlugin throws "collatedQuery.sort" in paginate method Jan 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant