Need a CouchDB trick to sort by date and filter by group



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

byDateGroup: {
  map: function(doc) {
    if ( && {
      emit([,], 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);

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.


Facebook Comments

Post a comment