PouchDB: filtering, ordering and paging

。_饼干妹妹 提交于 2019-12-10 07:51:18

问题


Very similar to these two CouchDB questions: 3311225 and 8924793, except that these approaches don't allow partial matching. Having e.g. these entries:

[{_id: 1, status: 'NEW', name: 'a'},
{_id: 2, status: 'NEW', name: 'aab'},
{_id: 3, status: 'NEW', name: 'ab'},
{_id: 4, status: 'NEW', name: 'aaa'},
{_id: 5, status: 'NEW', name: 'aa'}]

and key

[status, name, _id]

There seems to be no way to

  1. filter these entries by status (full string match) and name (partial string match ~ startsWith)
  2. order them by id
  3. paginate them

because of the partial string match on name. The high value unicode character \uffff that allows this partial match also causes to ignore the _id part of the key, meaning the resulting entries are not sorted by _id, but rather by status and name.

var status = 'NEW';
var name = 'aa'
var query = {
    startkey: [status, name],
    endkey: [status, name + '\uffff', {}],
    skip: 0,
    limit: 10
};

results in

[{_id: 5, status: 'NEW', name: 'aa'},
{_id: 4, status: 'NEW', name: 'aaa'},
{_id: 2, status: 'NEW', name: 'aab'}]

There is no option to sort in memory, as this would only sort the individual pages, and not the entire data set. Any ideas about this?

来源:https://stackoverflow.com/questions/41608361/pouchdb-filtering-ordering-and-paging

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