Reputation: 859
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);
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.
Upvotes: 5
Views: 4939
Reputation: 961
According to the official Mongo DB documentation what you have done is correct.
The second $options
argument to the find($filter, $options)
method supports the limit
and skip
keys, e.g.:
$options = [
"limit" => 10,
"skip" => 0
];
$results = $mongoCollection->find([], $options);
Upvotes: 2