How to do order in grouping(aggregation) in Couchbase?

244 views
Skip to first unread message

Prakash

unread,
May 26, 2014, 11:16:05 AM5/26/14
to couc...@googlegroups.com
have SQL query like this:
select count(id) as ct, city from table group by city order by ct desc

How can I perform this query in Couchbase? I have map function like This:

function (doc, meta) {
  if(doc.city!==null) {
  emit(doc.city,1)
    }
}

and reduce:

_count

my query url is like this: _view/q7?group_level=1&descending=true but it it sort only for key not for value.

No one had answer this here

http://stackoverflow.com/questions/23410708/how-to-do-order-in-groupingaggregation-in-couchbase

Aliaksey Kandratsenka

unread,
May 26, 2014, 1:32:32 PM5/26/14
to couc...@googlegroups.com
I believe it's impossible with couchdb-style views. Here's why.

What you need appears to require two sorting passes. One to group by city and get counts and another to sort by counts. And couchdb-style views only do one sorting (as part of placing view results into btree).

If only we could have views from views, then you could describe such dual-pass "topology" easily.

Gerald

unread,
May 27, 2014, 4:55:17 PM5/27/14
to couc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages