aravindnc / mongoose-paginate-v2

A custom pagination library for Mongoose with customizable labels.

Home Page:https://www.npmjs.com/package/mongoose-paginate-v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

filter the data?

Pradeep-Dhatarwal opened this issue · comments

can we filter the data coming based on some parameters like catefories and stuff?

@Pradeep-Dhatarwal You can pass query object based on your filter. The plugin will only take care of the pagination.

@Pradeep-Dhatarwal You can pass query object based on your filter. The plugin will only take care of the pagination.

Thanks mate

I'm fairly new with mongoose.
Can you please help me with this ? (newb question alert !!!)

let posts = await Post.paginate({category : req.query.category}, {
    page: req.query.page || 1,
    populate: "category",
    limit: 5,
    sort:{ "date": -1 }
});

here category needs to be populated first as it contains mongoose Object Id mapped to a category schema, but I'm unable to populate it and therefore can't filter the data.

therefore I'm not able to filter the results with category.