【问题标题】:Get selected latest 10 docs from couchDB order by timestamp按时间戳从 couchDB 顺序中获取选定的最新 10 个文档
【发布时间】:2014-05-01 13:09:51
【问题描述】:

当我运行下面的视图时,我会按时间排序文档。但是,如果我通过传递特定的 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

我需要得到最近 10 条记录,其 device_snoAxe001 按时间戳排序!

谁能帮我解决这个问题,这对我有很大帮助。 提前致谢!

【问题讨论】:

    标签: javascript mapreduce couchdb


    【解决方案1】:

    试试这个:

    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 会强制它匹配特定的键,但事实并非如此,因为键有两个元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-04
      • 2015-04-22
      • 2022-12-09
      • 1970-01-01
      • 1970-01-01
      • 2012-07-14
      相关资源
      最近更新 更多