aravindnc/mongoose-paginate-v2

the Query is not working well

xXm5aXx opened this issue · 3 comments

i wanna use a query like this {'Property.Price' : { $gte : 10}}. in find() function this query works but in paginate doesnt work

@mojtabasoleimani25 Please see the examples. If that didn't work, share the code block.

hello, I have the same problem.
I want to use myModel.find({ name: varName}) in mongoose-paginate-v2.
how to use find in mongoose-paginate-v2 ?

I tried this options but I retrieve all the documents.

 const options = {
    offset,
    limit,
    sort: { _id: -1 },
    select: {...},
    populate: [
      {...}
    ],
    options: { name: varName }
  };

let dataList = await myModel.paginate(condition, options, (err, result) => {
    return {
      totalItems: result.totalDocs,
      docs: result.docs,
      totalPages: result.totalPages,
      currentPage: result.page - 1
    };
  });

@MarwenBenTalebAli Here is a sample,

    var query = {
      title: {
        $in: [/Book/i],
      },
    };

    var options = {
      limit: 10,
      page: 5,
      lean: true,
    };

    return Book.paginate(query, options).then().catch()

More examples here:
https://github.com/aravindnc/mongoose-paginate-v2/blob/master/tests/index.js