1

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!

Shivansh
  • 3,454
  • 23
  • 46
  • without `descending` do you **only** get the desired results? shouldn't you use some form of `endKey` to restrain on a single `meta.id`? – Simon Baslé Sep 03 '15 at 08:08
  • If I am using the endKey=something then also it is giving me an empty List – Shivansh Sep 03 '15 at 08:25
  • We think it will require both a map and reduce in order to accomplish this. Can you provide some sample data and expected results? With that we can help you figure it out. We're going to need both a key and a value in your emit statement. – Nic Raboy Sep 03 '15 at 14:48

1 Answers1

1

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

FuzzyAmi
  • 7,543
  • 6
  • 45
  • 79