CouchDB sort doesn't work

让人想犯罪 __ 提交于 2019-12-06 15:16:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!