I am trying to limit a query return length with limit and skip but the returned array is an empty array. Here is the code snippet,
$start = 0;
$limit = 10;
$options = [
'skip' => $start,
'limit' => $limit,
];
$return = $db->collection->find([], $options);
- Collection has data (243 documents/rows to be exact)
- only find([]) does return those rows
- Im using mongodb/mongodb library via composer
- MongoDB PHP Plugin is the new one, installed via PECL mongodb-1.2.9
Is there something I am doing wrong? Is this a bug or a random thing?
Regards
PS: I know this is an already asked question, but most of the answers are related to the older extensions.
According to the official Mongo DB documentation what you have done is correct.
The second
$options
argument to thefind($filter, $options)
method supports thelimit
andskip
keys, e.g.: