CouchDB sort doesn't work

1.1k Views Asked by At

I recently started using CouchDB but I have no success with the sort-option using mango query.

My database is a simple person dataset and for this example I'd like to show all documents with the type "person" and sort it by the "firstName".

{
  "selector": {
    "type": "person"
  },
  "sort" : ["firstName"]
}

But it doesnt work. I just get the documents without any particular order.

enter image description here

This is the list of my indexes:

special: _id
json: gender
json: firstName
json: lastName

Is there something I forgot?


Edit:

As Alexis also pointed out, the docs say that the sorted field has to be present in the selector.

After testing around I figured out that the best way would be adding a greater than null condition to the field. That works in my case.

0

There are 0 best solutions below