0

I am using RESTHEART for accessing the service(API) and using NoSQL database mongoDB. So In MongoDb, I have 9000 records. If I am calling through RESTHEART then It is returning maximum only one thousand. So In one hit I am getting less then 10001 records. If I want to retrieve all records then I have to send again one more call.

I am attaching one flow of restheart and MongoDb
enter image description here

So based on restheart I am implementing angular data-table.

 <table datatable dt-options="datatables.standardOptions" dt-columns="datatables.standardColumns" class="table table-striped table-bordered table-hover" width="100%">
                <thead>
                  <tr>
                    <th>Id</th>
                    <th>Message</th>
                    <th>Exception Cause </th>               
                  </tr>
                </thead>

JS

  this.standardOptions = DTOptionsBuilder;
  this.standardOptions = DTOptionsBuilder
     .fromFnPromise(('api/tables/datatables.standard.json').getList())

    //Add Bootstrap compatibility
    .withDOM("<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>" +
    "t" +
    "<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>")
    .withBootstrap(); 

    this.standardColumns = [
    DTColumnBuilder.newColumn('_id').withOption('defaultContent', '-'),
    DTColumnBuilder.newColumn('msg').withOption('defaultContent', '-'),
    DTColumnBuilder.newColumn('exception_cause').withOption('defaultContent', '-'),

  ];

OUTPUT
enter image description here

In above screen shot only 100 page is coming. In 1 page has 10 records. Because restheart is not responding more then one thousand records. So How can we fix pagination count and pagination thing. Because I can get again more then one thousand record after click on next button in pagination. But still count is same 1000(total count of records is 2000) the user will confused.

For more understanding I am attaching screen shot.
enter image description here

Now it is coming like below:
enter image description here

So I want to fix with flexible code. I don't have much experience in restheart and angular datatable.

Varun Sharma
  • 4,632
  • 13
  • 49
  • 103

1 Answers1

0

in restheart paging is controlled via two query parameters: page and pagesize

pagesize maximum value is 1000

have a look at official documentation about paging

If you have 9000 documents, your requests can be:

GET /db/coll?pagesize=100&page=1
GET /db/coll?pagesize=100&page=2
....
GET /db/coll?pagesize=100&page=90

the following request will return no documents in the _embedded array:

GET /db/coll?pagesize=100&page=91 

To count the existing documents you need to add the count query parameter:

GET /db/coll?pagesize=100&page=1&count

The total number of documents is returned in the _size property

Note that this also works if you specify the filter qparam, example:

GET /db/coll?pagesize=100&page=1&count&filter={"a":1}
Andrea Di Cesare
  • 1,125
  • 6
  • 11
  • If one adds the `hal=f` query parameter to each GET can also activate [HAL mode](https://softinstigate.atlassian.net/wiki/spaces/RH/pages/9207888/Representation+Format#RepresentationFormat-Halmode) and get [pagination links](https://softinstigate.atlassian.net/wiki/spaces/RH/pages/10747996/Query+Documents#QueryDocuments-pagingPaging). – mturatti Feb 08 '18 at 08:28