如何从RESHTHEART获得超过一千(1000)条记录?

时间:2018-02-07 06:55:17

标签: angularjs mongodb datatables angular-datatables restheart

我使用RESTHEART访问服务(API)和使用NoSQL数据库mongoDB。所以在MongoDb中,我有9000条记录。如果我通过 RESTHEART 进行呼叫,那么它最多只返回一千。因此,在一次点击中,我得到的记录少于10001。如果我想要检索所有记录,那么我必须再发一次电话。

我附加了一个restheart流和MongoDb
enter image description here

所以基于restheart我正在实现角度数据表。

 <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', '-'),

  ];

输出
enter image description here

在上面的屏幕截图中,只有100页即将到来。在1页有10条记录。因为restheart没有响应超过一千条记录。 那么我们如何才能解决分页计数和分页问题。因为在点击下一个按钮后,我可以再次获得超过一千条记录。但仍然计数相同1000(记录总数是2000)用户会感到困惑。

为了更加了解,我附加了截屏。
enter image description here

现在它如下:
enter image description here

所以我想修复灵活的代码。我在restheart和angular datatable方面没有太多经验。

1 个答案:

答案 0 :(得分:0)

在restheart分页中的

是通过两个查询参数控制的:页面 pagesize

pagesize 最大值为1000

查看有关paging

的官方文档

如果您有9000个文档,您的请求可以是:

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

以下请求将不会在_embedded数组中返回任何文档:

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

要计算现有文档,您需要添加计数查询参数:

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

_size 属性

中返回文档总数

请注意,如果您指定过滤器 qparam,这也有效,例如:

GET /db/coll?pagesize=100&page=1&count&filter={"a":1}
相关问题