MongoDB休息服务中的offset始终为0

时间:2016-05-02 21:58:07

标签: mongodb rest offset

我想滚动浏览mongodb REST响应的所有页面。

ubuntu@ubuntu:/etc$ curl http://localhost:28017/bb/feeds/?limit=1

没有偏移我得到正确的结果

  {
  "offset" : 0,
  "rows": [
    { "_id" : { "$oid" : "57254bd21d41c82413afed60" }, "variety" : "Other", "modal_price" : "2150", "commodity" : "Rice", "max_price" : "2200", "state" : "West Bengal", "min_price" : "2100", "district" : "Uttar Dinajpur", "timestamp" : "1462026632", "market" : "Islampur", "id" : "87200341", "arrival_date" : "30/04/2016" }
  ],

  "total_rows" : 1 ,
  "query" : {} ,
  "millis" : 0
}

但是当我通过偏移= 2 时,我仍然得到相同的结果

ubuntu@ubuntu:/etc$ curl http://localhost:28017/bb/feeds/?limit=1&offset=2

{
  "offset" : 0,
  "rows": [
    { "_id" : { "$oid" : "57254bd21d41c82413afed60" }, "variety" : "Other", "modal_price" : "2150", "commodity" : "Rice", "max_price" : "2200", "state" : "West Bengal", "min_price" : "2100", "district" : "Uttar Dinajpur", "timestamp" : "1462026632", "market" : "Islampur", "id" : "87200341", "arrival_date" : "30/04/2016" }
  ],

  "total_rows" : 1 ,
  "query" : {} ,
  "millis" : 0
} 

1 个答案:

答案 0 :(得分:2)

您需要传递的网址参数实际为skip,而不是offset

curl http://localhost:28017/bb/feeds/?limit=1&skip=2

...有些令人困惑的是在JSON输出中表示为offset值。

注意:MongoDB中的内置REST接口在功能和安全性方面非常有限,并且在MongoDB 3.2中已弃用。我强烈建议您研究一种替代(并积极维护)的REST API。有关起点,请参阅MongoDB手册中的HTTP Interfaces