{"action":"created","issue":{"url":"https://api.github.com/repos/robconery/massive-js/issues/223","repository_url":"https://api.github.com/repos/robconery/massive-js","labels_url":"https://api.github.com/repos/robconery/massive-js/issues/223/labels{/name}","comments_url":"https://api.github.com/repos/robconery/massive-js/issues/223/comments","events_url":"https://api.github.com/repos/robconery/massive-js/issues/223/events","html_url":"https://github.com/robconery/massive-js/issues/223","id":140221369,"number":223,"title":"How to sort a document query by a document field","user":{"login":"subblue","id":3010,"avatar_url":"https://avatars.githubusercontent.com/u/3010?v=3","gravatar_id":"","url":"https://api.github.com/users/subblue","html_url":"https://github.com/subblue","followers_url":"https://api.github.com/users/subblue/followers","following_url":"https://api.github.com/users/subblue/following{/other_user}","gists_url":"https://api.github.com/users/subblue/gists{/gist_id}","starred_url":"https://api.github.com/users/subblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/subblue/subscriptions","organizations_url":"https://api.github.com/users/subblue/orgs","repos_url":"https://api.github.com/users/subblue/repos","events_url":"https://api.github.com/users/subblue/events{/privacy}","received_events_url":"https://api.github.com/users/subblue/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-11T16:00:05Z","updated_at":"2016-03-11T16:14:57Z","closed_at":null,"body":"I'm just getting started with Massive, so forgive my noobness...  \r\n\r\nI have a `projects` table filed with project documents that were stored using the standard `saveDoc()` method. I would like to retrieve a limited list of projects sorted by an `updatedAt` field that is within the document body.\r\n\r\nI've tried things like this without luck:\r\n```javascript\r\ndb.find({}, {order: 'body->>updatedAt', limit: 10}, callback);\r\n```\r\n\r\nWhat is the best process to do this (or do I need to store the updatedAt field outside the body as a standard date column)?\r\n\r\nOn a related matter, is it possible to only include only some of the fields from the document in the result set (like we can use the `columns` option for normal queries), or is that something that has to be done after the query?\r\n\r\nThanks."},"comment":{"url":"https://api.github.com/repos/robconery/massive-js/issues/comments/195434262","html_url":"https://github.com/robconery/massive-js/issues/223#issuecomment-195434262","issue_url":"https://api.github.com/repos/robconery/massive-js/issues/223","id":195434262,"user":{"login":"subblue","id":3010,"avatar_url":"https://avatars.githubusercontent.com/u/3010?v=3","gravatar_id":"","url":"https://api.github.com/users/subblue","html_url":"https://github.com/subblue","followers_url":"https://api.github.com/users/subblue/followers","following_url":"https://api.github.com/users/subblue/following{/other_user}","gists_url":"https://api.github.com/users/subblue/gists{/gist_id}","starred_url":"https://api.github.com/users/subblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/subblue/subscriptions","organizations_url":"https://api.github.com/users/subblue/orgs","repos_url":"https://api.github.com/users/subblue/repos","events_url":"https://api.github.com/users/subblue/events{/privacy}","received_events_url":"https://api.github.com/users/subblue/received_events","type":"User","site_admin":false},"created_at":"2016-03-11T16:14:57Z","updated_at":"2016-03-11T16:14:57Z","body":"Just to answer my own immediate question I realised it is probably easier to create the SQL directly and then use the `db.run(sql, callback)` method:\r\n\r\n```sql\r\nSELECT id, body->>'title' AS title, body->>'updatedAt' AS updated_at\r\nFROM projects\r\nORDER BY body->>'updatedAt' DESC\r\nLIMIT 10\r\n```\r\n\r\n...still getting used to the new JSON capabilities in Postgres ;)"}}