A simple and fast way to paginate your mongoose query results on Nestjs
- mongoose >= 8.0.0
To paginate items, you just need to call the function and pass the query as parameter. Just like this :
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { paginate } from 'nestjs-paginate-mongo';
import { Post, PostDocument } from './entities/post.entity';
@Injectable()
export class PostsService {
constructor(
@InjectModel(Post.name) private readonly posts: Model<PostDocument>,
) {}
findAll() {
return paginate(this.posts.find());
}
}
And voila, you got your paginated data.
- If you have any problem about this package or a suggestion, dont hesitate to inform me by creating an issue
- Are you a lovely developer and you think you can help by fixing a submitted issue ? Then I'll be glad to merge a PR from you 😊
Enjoying this little package ? You can support me 🙏