PHP - 获取CouchDB中的最后一行

时间:2013-05-08 23:41:45

标签: php database nosql couchdb

我正在尝试使用PHP找到在CouchDB中获取最后一行的方法。我一直在四处寻找,而且我找不到很多有用的东西。

感谢。

1 个答案:

答案 0 :(得分:1)

这本身并不是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个结果后停止(参见参考here)。