需要一个CouchDB技巧来按日期排序并按组过滤 [英] Need a CouchDB trick to sort by date and filter by group

查看:140
本文介绍了需要一个CouchDB技巧来按日期排序并按组过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有字段'date'和'group'的文档。这是我的观点:

  byDateGroup:{
map:function(doc){
if doc.date&& doc.group){
emit([doc.date,doc.group],null);
}
}
}

什么是等效查询其中:

  select * from docs where group in(group1,group2)order by date desc 

这个简单的解决方案不是我的头脑。 :(

解决方案

Pankaj,切换您要发送的密钥顺序:

  emit([doc.group,doc.date],doc); 

然后,您可以在查询视图时传入一个开始键和一个结束键。对于您要提取数据的每个组,可能会更容易做一个单独的查询,数据将按日期排序。



目前我正在出路,但如果不清楚,我可以详细说明一下。


I have documents with fields 'date' and 'group'. And this is my view:

byDateGroup: {
  map: function(doc) {
    if (doc.date && doc.group) {
      emit([doc.date, doc.group], null);
    }
  }
}

What would be the equivalent query of this:

select * from docs where group in ("group1", "group2") order by date desc

This simple solution is not coming into my head. :(

解决方案

Pankaj, switch the order of the key you're emitting to this:

emit([doc.group, doc.date], doc);

Then you can pass in a start key and an end key when querying the view. It might be easier to do a separate query for each group that you want to pull data for. The data will be sorted by date.

I'm on my way out at the moment, but can elaborate more when I get back if it isn't clear.

这篇关于需要一个CouchDB技巧来按日期排序并按组过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆