{"action":"created","issue":{"url":"https://api.github.com/repos/nolanlawson/pouchdb-find/issues/147","labels_url":"https://api.github.com/repos/nolanlawson/pouchdb-find/issues/147/labels{/name}","comments_url":"https://api.github.com/repos/nolanlawson/pouchdb-find/issues/147/comments","events_url":"https://api.github.com/repos/nolanlawson/pouchdb-find/issues/147/events","html_url":"https://github.com/nolanlawson/pouchdb-find/issues/147","id":127939920,"number":147,"title":"Can't seem to be able to sort by ascending order?","user":{"login":"yattias","id":802819,"avatar_url":"https://avatars.githubusercontent.com/u/802819?v=3","gravatar_id":"","url":"https://api.github.com/users/yattias","html_url":"https://github.com/yattias","followers_url":"https://api.github.com/users/yattias/followers","following_url":"https://api.github.com/users/yattias/following{/other_user}","gists_url":"https://api.github.com/users/yattias/gists{/gist_id}","starred_url":"https://api.github.com/users/yattias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yattias/subscriptions","organizations_url":"https://api.github.com/users/yattias/orgs","repos_url":"https://api.github.com/users/yattias/repos","events_url":"https://api.github.com/users/yattias/events{/privacy}","received_events_url":"https://api.github.com/users/yattias/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-21T14:45:25Z","updated_at":"2016-01-22T15:08:55Z","closed_at":null,"body":"Hi Pouchdb-find team,\r\n\r\nI have the following query: \r\n\r\n      var searchQuery = {\r\n        selector: {\r\n          $and: [\r\n            {_id:  {$gt: null}}\r\n          ],\r\n          sort: [{_id: 'asc'}]\r\n        }\r\n      };\r\n\r\nBut my results are not sorted correctly.\r\n\r\n\"_id\" is a string in my database. Each record has the following:\r\n\r\n![screen shot 2016-01-21 at 9 42 55 am](https://cloud.githubusercontent.com/assets/802819/12483517/7ba0cd96-c023-11e5-9681-863e981cf0bd.png)\r\n\r\nThe function responsible for executing the query is:\r\n\r\n```\r\nStore.prototype.getDocsByQuery = function(query){\r\n  var db = this.localDB;\r\n  return new Promise(function(resolve, reject){\r\n    db.find(query).then(function(result){\r\n      resolve(result.docs);\r\n    }).catch(function(err){\r\n      console.log(\"Error\", err);\r\n    });\r\n  });\r\n};\r\n```\r\n\r\nAny insight into what is happening?"},"comment":{"url":"https://api.github.com/repos/nolanlawson/pouchdb-find/issues/comments/173944983","html_url":"https://github.com/nolanlawson/pouchdb-find/issues/147#issuecomment-173944983","issue_url":"https://api.github.com/repos/nolanlawson/pouchdb-find/issues/147","id":173944983,"user":{"login":"cemarta7","id":5060049,"avatar_url":"https://avatars.githubusercontent.com/u/5060049?v=3","gravatar_id":"","url":"https://api.github.com/users/cemarta7","html_url":"https://github.com/cemarta7","followers_url":"https://api.github.com/users/cemarta7/followers","following_url":"https://api.github.com/users/cemarta7/following{/other_user}","gists_url":"https://api.github.com/users/cemarta7/gists{/gist_id}","starred_url":"https://api.github.com/users/cemarta7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cemarta7/subscriptions","organizations_url":"https://api.github.com/users/cemarta7/orgs","repos_url":"https://api.github.com/users/cemarta7/repos","events_url":"https://api.github.com/users/cemarta7/events{/privacy}","received_events_url":"https://api.github.com/users/cemarta7/received_events","type":"User","site_admin":false},"created_at":"2016-01-22T15:08:55Z","updated_at":"2016-01-22T15:08:55Z","body":"Im having the same problem when trying to sort.\r\n\r\ndb.createIndex({\r\n      index: {\r\n        fields: ['name','type'],\r\n        name:\"contacts\"\r\n      }\r\n    })\r\n\r\ndb.find({\r\n        selector: {\r\n          name: { $gt: null },\r\n          type: { $eq: 'contact' }\r\n        },\r\n        fields: ['_id', 'name'],\r\n        sort:[{'name':'asc'}]\r\n      })\r\n\r\nsorting is happening by _id not by name\r\n"}}