0

Are there any good Practices for using Dynomoose.js to implement pagination with Angular. I would like to use scan.limit() in order to get some amount of Movies from the DB, for example, 20. How do I get the second scan 20-40 Movies and 40-60 Movies? Should I use scan.startAt(key) in order to retrieve further data?

exports.listing = (req, res, next) => {
  MoviesModel.scan()
    .exec()
    .then(movies=> {
      if(movies.lastKey){
        MovieModel.scan().startAt(movies.lastKey).exec(function(err, movies){
          res.json(movies);
        });
      }  
     })
    .catch(err => next(err));
};
KalinJa
  • 483
  • 1
  • 4
  • 8

1 Answers1

0

An easy way is always here is to perform pagination in the client side using for example ngx-pagination see here :

    <ul>
      <li *ngFor="let item of collection | paginate: { itemsPerPage: 10, currentPage: p }"> ... </li>
    </ul>

    <pagination-controls (pageChange)="p = $event"></pagination-controls>

In the backend just return all your records Model.scan().exec() and store them in collection property :

exports.listing = (req, res, next) => {
  MoviesModel.scan()
    .exec()
    .then(movies=> {
      if(movies.lastKey){
        MovieModel.scan().exec(function(err, movies){
          res.json(movies);
        });
      }  
     })
    .catch(err => next(err));
};
  • Thank you, but the exact Problem is that i can't take the all data bacause i am restricted from AWS (Amazon Web Service) to beckome no more from 1 mb data. And now i want to get only the data that i need and to make it less than 1 mb. – KalinJa Jul 04 '19 at 10:53
  • 1
    Okay I see. check this link it's can help https://www.talentica.com/blogs/dynamo-db-pagination/ – Abderrahim Soubai-Elidrisi Jul 04 '19 at 11:07