{"action":"created","issue":{"url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/195","repository_url":"https://api.github.com/repos/mongodb/mongo-php-driver","labels_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/195/labels{/name}","comments_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/195/comments","events_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/195/events","html_url":"https://github.com/mongodb/mongo-php-driver/issues/195","id":125039569,"number":195,"title":"Cant count result ","user":{"login":"metalwolf","id":1404459,"avatar_url":"https://avatars.githubusercontent.com/u/1404459?v=3","gravatar_id":"","url":"https://api.github.com/users/metalwolf","html_url":"https://github.com/metalwolf","followers_url":"https://api.github.com/users/metalwolf/followers","following_url":"https://api.github.com/users/metalwolf/following{/other_user}","gists_url":"https://api.github.com/users/metalwolf/gists{/gist_id}","starred_url":"https://api.github.com/users/metalwolf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metalwolf/subscriptions","organizations_url":"https://api.github.com/users/metalwolf/orgs","repos_url":"https://api.github.com/users/metalwolf/repos","events_url":"https://api.github.com/users/metalwolf/events{/privacy}","received_events_url":"https://api.github.com/users/metalwolf/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-01-05T20:02:23Z","updated_at":"2016-12-29T16:39:55Z","closed_at":"2016-02-23T15:05:32Z","body":"ON previous mongo driver you had all the result functions ->count()\nIt seems the new driver lacks the counting function\n\n$coleccion->find()->count() is missing, it is impossible to count result on phongo\n"},"comment":{"url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/comments/269656704","html_url":"https://github.com/mongodb/mongo-php-driver/issues/195#issuecomment-269656704","issue_url":"https://api.github.com/repos/mongodb/mongo-php-driver/issues/195","id":269656704,"user":{"login":"jmikola","id":244663,"avatar_url":"https://avatars.githubusercontent.com/u/244663?v=3","gravatar_id":"","url":"https://api.github.com/users/jmikola","html_url":"https://github.com/jmikola","followers_url":"https://api.github.com/users/jmikola/followers","following_url":"https://api.github.com/users/jmikola/following{/other_user}","gists_url":"https://api.github.com/users/jmikola/gists{/gist_id}","starred_url":"https://api.github.com/users/jmikola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmikola/subscriptions","organizations_url":"https://api.github.com/users/jmikola/orgs","repos_url":"https://api.github.com/users/jmikola/repos","events_url":"https://api.github.com/users/jmikola/events{/privacy}","received_events_url":"https://api.github.com/users/jmikola/received_events","type":"User","site_admin":false},"created_at":"2016-12-29T16:39:55Z","updated_at":"2016-12-29T16:39:55Z","body":"> I guess this is very similar to PHPLIB-81, but using the built-in IteratorIterator class to decorate the cursor. I have no idea how the valid method works, but so far it's getting the job done. It seems like CachingIterator::hasNext would be more appropriate.\r\n\r\nWe already use IteratorIterator in the library to decorate a Cursor object (see: [CollectionInfoCommandIterator](https://github.com/mongodb/mongo-php-library/blob/1.1.0/src/Model/CollectionInfoCommandIterator.php)). IteratorIterator is useful for decorating any Traversable and exposing methods to the underlying handlers (e.g. get current element/key, rewind, move forward). In this case, `IteratorIterator::valid()` will directly call [`php_phongo_cursor_iterator_valid()`](https://github.com/mongodb/mongo-php-driver/blob/1.2.2/src/MongoDB/Cursor.c#L80) and return whether there is a current element. For a new Cursor, this requires us to attempt populating the first element, which is exactly what you achieve by calling `IteratorIterator::rewind()` (i.e. [`php_phongo_cursor_iterator_rewind()`](https://github.com/mongodb/mongo-php-driver/blob/1.2.2/src/MongoDB/Cursor.c#L146)).\r\n\r\nThe downside of your approach is that you're executing one query for each page in sequence, which means more roundtrips and cursors/queries on the server side.\r\n\r\n> I thought it might be possible to accomplish this with Mongo's batchSize option, but as far as I can tell, this wouldn't actually work as it is internal to the driver, is that correct?\r\n\r\n`batchSize` is used to control how many documents are provided to the driver at a time over the wire protocol (see: [`find` command docs](https://docs.mongodb.com/manual/reference/command/find/)). For instance, a small batch size would entail more roundtrips to the database to iterate across a result set. This is largely transparent to the application.\r\n\r\n> If you are expecting to work with big result sets you should also consider writing a custom chunk method for that collection and use something that can be found via an index, e.g. using ObjectID ranges for chunking the result set, since the skip + limit method isn't ideal for huge collections.\r\n\r\nPagination via index ranges is absolutely more performant than using `skip` to advance to later \"pages\" in the result set.  You should certainly look into this approach."}}
{"actor":{"display_login":"jmikola"}}