Skip to content

sidikfaha/nestjs-paginate-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Total Downloads Latest Stable Version

Nestjs Paginate Mongo

A simple and fast way to paginate your mongoose query results on Nestjs

Requiements

  • mongoose >= 8.0.0

How to use

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.

Contribution

  • 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 😊

Support me

Enjoying this little package ? You can support me 🙏

"Buy Me A Coffee"