Shivansh
Shivansh

Reputation: 3544

Couchbase View : Sorting on Keys

I am using Couchbase 3.0 and I have a use case where I want to perform sorting, but as i cam through couchbase does not provide Sorting on Values but it provides Sorting on Keys, But as I use descending(true) it is returning me empty list. And on the other hand If I just simply use it without descending then it is giving me all the docs related.

My Map function is :

function (doc, meta) {
  emit([meta.id,doc.latest.sortData],null);
}
}

Now my use case is that I want to perform a match query on meta.id and then for all the matched cases sort the data and then find out the top values.

The code that i am using to so is :

ViewQuery.from(DesignDocName, viewName).startKey(JsonArray.from(write(List("something","")))).descending(true).limit(5).stale(Stale.FALSE))

If I remove the descending parameter then I get the related rows but they are not sorted. So could you please provide me a way in which this can be done.

Any Help is appreciated

Thanks!

Upvotes: 1

Views: 532

Answers (1)

FuzzyAmi
FuzzyAmi

Reputation: 8119

I was reading Couchbase's docs and stumbled upon this line:

Because selection is made after sorting the view results, if you configure the results to be sorted in descending order and you are selecting information using a key range, then you must also reverse the startkey and endkey parameters.

see here: http://docs.couchbase.com/admin/admin/Views/views-querying.html#ordering

Upvotes: 1

Related Questions