Reputation:
I work with mongodb and i have a simple request to do. I use "find" and i want to limit the result it gets. I have seen the functions "skip" and "limit" of MongoCursor but i want to use the $limit and $skip properties in the query and not with the cursor to limit the data returned.
In the mongodb documentation that seems possible but my request return nothing if I try like this :
$myMongoDB->myCollection->find(array('type' => 'test', '$limit' => 10);
Or :
$myMongoDB->myCollection->find(array('$query' => array('type' => 'test'), '$limit' => 10);
Anyone could help me to see what i do wrong ?
Thank's for help.
PS : and sorry for the quality of my english...
Upvotes: 0
Views: 3536
Reputation: 43884
I have no idea why you want to do this however:
$cursor = $collection->find(array('type' => 'test'));
$cursor->addOption( '$maxScan', 10 );
$maxScan
is $limit
and $orderby
is $sort
.
Reference: http://docs.mongodb.org/manual/reference/operator/query-modifier/
Upvotes: 3