问题
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.
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.
来源:https://stackoverflow.com/questions/47507031/couchdb-sort-doesnt-work