我正在尝试找到一种使用 PHP 获取 CouchDB 中最后一行的方法。我四处搜寻,并没有发现太多有用的东西。
谢谢。
这本身并不是特定于 PHP 的,但这听起来像是 CouchDB 降序和限制参数的工作:
$ curl -X GET 'http://localhost:5984/test2/_design/test_views/_view/view1'
{"total_rows":4,"offset":0,"rows":[
{"id":"test1","key":["account1","2009-05-13T11:59:22.281Z"],"value":{"rel":"account1"}},
{"id":"test2","key":["account2","2012-05-13T11:59:22.281Z"],"value":{"rel":"account2"}},
{"id":"test3","key":["account3","2011-05-13T11:59:22.281Z"],"value":{"rel":"account3"}},
{"id":"test4","key":["account4","2010-05-13T11:59:22.281Z"],"value":{"rel":"account4"}}
]}
$ curl -X GET 'http://localhost:5984/test2/_design/test_views/_view/view1?descending=true&limit=1'
{"total_rows":4,"offset":0,"rows":[
{"id":"test4","key":["account4","2010-05-13T11:59:22.281Z"],"value":{"rel":"account4"}}
]}
降序颠倒顺序,在 n 个结果后停止(请参阅此处的参考)。