{"action":"created","issue":{"url":"https://api.github.com/repos/nviennot/nobrainer/issues/147","labels_url":"https://api.github.com/repos/nviennot/nobrainer/issues/147/labels{/name}","comments_url":"https://api.github.com/repos/nviennot/nobrainer/issues/147/comments","events_url":"https://api.github.com/repos/nviennot/nobrainer/issues/147/events","html_url":"https://github.com/nviennot/nobrainer/issues/147","id":83023703,"number":147,"title":"[HowTo] Retrieve the newer document with the lower value ?","user":{"login":"zedtux","id":478564,"avatar_url":"https://avatars.githubusercontent.com/u/478564?v=3","gravatar_id":"","url":"https://api.github.com/users/zedtux","html_url":"https://github.com/zedtux","followers_url":"https://api.github.com/users/zedtux/followers","following_url":"https://api.github.com/users/zedtux/following{/other_user}","gists_url":"https://api.github.com/users/zedtux/gists{/gist_id}","starred_url":"https://api.github.com/users/zedtux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zedtux/subscriptions","organizations_url":"https://api.github.com/users/zedtux/orgs","repos_url":"https://api.github.com/users/zedtux/repos","events_url":"https://api.github.com/users/zedtux/events{/privacy}","received_events_url":"https://api.github.com/users/zedtux/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-31T07:08:20Z","updated_at":"2015-05-31T16:38:09Z","closed_at":"2015-05-31T08:23:51Z","body":"Given the following model:\r\n\r\n```ruby\r\nclass User\r\n  include NoBrainer::Document\r\n  include NoBrainer::Document::Timestamps\r\n\r\n  field :friends_count, type: Fixnum, required: true\r\n\r\n  ...\r\nend\r\n```\r\n\r\nI would like to retrieve the `User` created the sooner:\r\n\r\n - with the higher amount of friends\r\n - with the lower amount of friends\r\n\r\nI did the first point using `max` (with a block to pass the 2 fields `:friends_count` and `:created_at`).\r\nNow for the second point, using `min` is giving me the older with the less friends but I want the newer.\r\n\r\nWhat is the best way to achieve this ? Is there a nice method to do this or do I have to build a `where` ?"},"comment":{"url":"https://api.github.com/repos/nviennot/nobrainer/issues/comments/107221020","html_url":"https://github.com/nviennot/nobrainer/issues/147#issuecomment-107221020","issue_url":"https://api.github.com/repos/nviennot/nobrainer/issues/147","id":107221020,"user":{"login":"zedtux","id":478564,"avatar_url":"https://avatars.githubusercontent.com/u/478564?v=3","gravatar_id":"","url":"https://api.github.com/users/zedtux","html_url":"https://github.com/zedtux","followers_url":"https://api.github.com/users/zedtux/followers","following_url":"https://api.github.com/users/zedtux/following{/other_user}","gists_url":"https://api.github.com/users/zedtux/gists{/gist_id}","starred_url":"https://api.github.com/users/zedtux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zedtux/subscriptions","organizations_url":"https://api.github.com/users/zedtux/orgs","repos_url":"https://api.github.com/users/zedtux/repos","events_url":"https://api.github.com/users/zedtux/events{/privacy}","received_events_url":"https://api.github.com/users/zedtux/received_events","type":"User","site_admin":false},"created_at":"2015-05-31T16:38:09Z","updated_at":"2015-05-31T16:38:09Z","body":"OK. My first try was `.min(:friends_count).max(created_at)` but as you're using `first` it's giving an object. Now I don't really know if chaining `min` and `max` would make sense ..."}}