pouchdb: Sorting with selector $exists uses the wrong index
From @dolfje on September 8, 2016 10:27
When trying to sort on a field that is only selected by the $exists selector, gives an error.
testDB = new PouchDB(‘test’); testDB.createIndex({index: {fields: [“test”]}}).then(function() { return testDB.put({_id: “”+Math.random(), “test”: 5}); }).then(function() { return testDB.find({selector:{“test”: {$exists: true}}, sort: [“test”]}); }).then(function(ret) { // Expect result, only get //Error: Cannot sort on field(s) “test” when using the default index });`
Copied from original issue: nolanlawson/pouchdb-find#212
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 22 (7 by maintainers)
Commits related to this issue
- (#6266) - Allow regex, type and exists checks to use index when sorting — committed to pouchdb/pouchdb by daleharvey 6 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Why closing this issue ? I think this should be resolve without workaround as shown before…
I got this working by adding a gt: null with and selector like this :
I’ve solved this problem on my side, using JS function sort. Like this:
Note that this issue also happens when using the $type selector filter.