如果日期存储在整数数组中,couchDB 按日期对结果数组进行排序?

couchDB sort result array by date if date is stored in an array of integers?

我正在存储 couchDB 文档,它们有一个属性 date,我想按该属性进行排序。

{

  ...blahblah...

  "date": [
    2015,
    5,
    16
  ]
}

我似乎无法弄清楚如何创建允许我提供 startdate=[2015,5,1]&enddate=[2015,5,31] 查询的视图。我想买 5 月(第 5 个月)的东西

它应该像这样简单:

function (doc) {
  emit(doc.date);
}

那么您的查询需要是:start_key=[2015,5,1]&end_key=[2015,5,31]

查看 documentation

或者,如果日期字段指定的文档是按顺序创建的(即字段日期=“2015、4、16”的文档先于字段日期=“2015、4、20”的文档创建) . 在这种情况下,您还可以使用创建文档时的时间戳进行排序。

function(doc) { 

emit([doc.created_at,doc.date], doc);
}

http://wiki.apache.org/couchdb/View_collation