mixmaxhq / mongo-cursor-pagination

Cursor-based pagination for Mongo
https://www.mixmax.com/careers
MIT License
229 stars 72 forks source link

Ignores Schema if used as Mongoose Plugin #47

Open uncledent opened 6 years ago

uncledent commented 6 years ago

It ignores virtuals and hidden fields with { select: false }.

Does anyone know a workaround for that?

uncledent commented 6 years ago

If you need just the mongoose plugin which will use your mongoose model, you can try this lib: https://github.com/uncledent/mongoose-cursor-pagination-plugin

It is fully based on this library, but there is the mongoose plugin only, other stuff is removed. It uses mongoose model instead of raw mongo driver.

sangdth commented 4 years ago

I have tried your plugin but I face another problem. When I use with nestjs, I have to declare the model while injecting:

    @InjectModel('Item') private ItemModel: PaginateModel<Item>

In your plugin there is no PaginateModel so the nest can not work, do you have another solution for this? I really need to make the virtual works.

uncledent commented 4 years ago

@sangdth You can just create an interface by your own and use it:

export interface PaginatedModel<T extends Document> extends Model<T> {
  paginate(paginantionOptions: any): PaginationResult<T>;
}