当我运行下面的 View 时,我将按时间顺序获取文档。但是如果我通过传递特定的 device_sno 来调用像下面这样的 URL,它就不起作用......
查看:
function(doc){
emit([doc.device_sno,doc.timestamp],doc);
}
网址:
http://localhost:5984/trip_test/_design/test/_view/test?key=["Axe001"]&limit=10&ascending=true&include_docs=true
我需要按时间戳获取 device_sno
为 Axe001
的最后 10 条记录!
谁能帮我解决这个问题,这对我有很大帮助。 提前致谢!
最佳答案
试试这个:
http://localhost:5984/trip_test/_design/test/_view/test?start_key=["Axe001"]&limit=10&end_key=["Axe001", {}]
这将为您提供前 10 项。要获取最后 10 个,请执行以下操作:
http://localhost:5984/trip_test/_design/test/_view/test?end_key=["Axe001"]&limit=10&start_key=["Axe001", {}]&descending=true
放置 key
会强制它匹配该特定键,但事实并非如此,因为键有两个元素。
关于javascript - 按时间戳顺序从 couchDB 中获取选定的最新 10 个文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23408351/