{"action":"created","issue":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4517","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4517/labels{/name}","comments_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4517/comments","events_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4517/events","html_url":"https://github.com/rethinkdb/rethinkdb/issues/4517","id":93867964,"number":4517,"title":"Add a method akin to cursor.hasNext()","user":{"login":"andyburke","id":273857,"avatar_url":"https://avatars.githubusercontent.com/u/273857?v=3","gravatar_id":"","url":"https://api.github.com/users/andyburke","html_url":"https://github.com/andyburke","followers_url":"https://api.github.com/users/andyburke/followers","following_url":"https://api.github.com/users/andyburke/following{/other_user}","gists_url":"https://api.github.com/users/andyburke/gists{/gist_id}","starred_url":"https://api.github.com/users/andyburke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyburke/subscriptions","organizations_url":"https://api.github.com/users/andyburke/orgs","repos_url":"https://api.github.com/users/andyburke/repos","events_url":"https://api.github.com/users/andyburke/events{/privacy}","received_events_url":"https://api.github.com/users/andyburke/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/labels/tp:ReQL_proposal","name":"tp:ReQL_proposal","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/milestones/41","html_url":"https://github.com/rethinkdb/rethinkdb/milestones/subsequent","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/milestones/41/labels","id":367201,"number":41,"title":"subsequent","description":"","creator":{"login":"coffeemug","id":48436,"avatar_url":"https://avatars.githubusercontent.com/u/48436?v=3","gravatar_id":"","url":"https://api.github.com/users/coffeemug","html_url":"https://github.com/coffeemug","followers_url":"https://api.github.com/users/coffeemug/followers","following_url":"https://api.github.com/users/coffeemug/following{/other_user}","gists_url":"https://api.github.com/users/coffeemug/gists{/gist_id}","starred_url":"https://api.github.com/users/coffeemug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coffeemug/subscriptions","organizations_url":"https://api.github.com/users/coffeemug/orgs","repos_url":"https://api.github.com/users/coffeemug/repos","events_url":"https://api.github.com/users/coffeemug/events{/privacy}","received_events_url":"https://api.github.com/users/coffeemug/received_events","type":"User","site_admin":false},"open_issues":349,"closed_issues":0,"state":"open","created_at":"2013-06-30T07:32:52Z","updated_at":"2015-07-10T00:35:01Z","due_on":null,"closed_at":null},"comments":15,"created_at":"2015-07-08T19:18:46Z","updated_at":"2015-07-10T00:36:31Z","closed_at":null,"body":"It would be nice to have a simple, straightforward way to know if a cursor has any (more) items. \r\n\r\nCoercing it to an array and checking for that array to be empty is not (I wouldn't think) efficient, especially if there many records.\r\n\r\nThe existing each() and next() methods don't make this easy or straightforward.\r\n\r\nThe use case I am looking at right now is checking for existing users in a database who have the same email address or phone number. Currently, I am doing:\r\n\r\n```javascript\r\n        var error = null;\r\n        var existing = null;\r\n        cursor.each( function( _error, _user ) {\r\n            error = _error;\r\n            existing = _user;\r\n            cursor.close();\r\n        }, function() {\r\n            if ( error ) {\r\n                callback( error );\r\n                return;\r\n            }\r\n\r\n            if ( existing ) {\r\n                callback( 'Existing user!' );\r\n            }\r\n\r\n            callback();\r\n        } );\r\n```\r\n\r\nIt would be much nicer to be able to do:\r\n\r\n```javascript\r\n    if ( cursor.hasNext() ) {\r\n        callback( 'Existing user!' );\r\n        return;\r\n    }\r\n```\r\n\r\nIf, however, it needs to be asynchronous, it still seems more straightforward than the each()/cursor.close() construction above:\r\n\r\n```javascript\r\n    cursor.hasNext( function( error, hasNext ) {\r\n        callback( hasNext ? 'Existing user!' : error );\r\n    } );\r\n```"},"comment":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/comments/120182872","html_url":"https://github.com/rethinkdb/rethinkdb/issues/4517#issuecomment-120182872","issue_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/4517","id":120182872,"user":{"login":"danielmewes","id":505365,"avatar_url":"https://avatars.githubusercontent.com/u/505365?v=3","gravatar_id":"","url":"https://api.github.com/users/danielmewes","html_url":"https://github.com/danielmewes","followers_url":"https://api.github.com/users/danielmewes/followers","following_url":"https://api.github.com/users/danielmewes/following{/other_user}","gists_url":"https://api.github.com/users/danielmewes/gists{/gist_id}","starred_url":"https://api.github.com/users/danielmewes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielmewes/subscriptions","organizations_url":"https://api.github.com/users/danielmewes/orgs","repos_url":"https://api.github.com/users/danielmewes/repos","events_url":"https://api.github.com/users/danielmewes/events{/privacy}","received_events_url":"https://api.github.com/users/danielmewes/received_events","type":"User","site_admin":false},"created_at":"2015-07-10T00:36:31Z","updated_at":"2015-07-10T00:36:31Z","body":"Marking as a ReQL_proposal for an optarg for `next`.\r\n\r\nWould it actually make it any easier to handle though if `next` called the callback with `null` and no error rather than `null` and an error?"}}