我和mongodb合作,我有一个简单的要求。我使用“查找”,我想限制它得到的结果。我已经看到了MongoCursor的“跳过”和“限制”功能,但我想在查询中使用$ limit和$ skip属性,而不是用光标来限制返回的数据。
在看似可能的mongodb文档中,如果我尝试这样做,我的请求就不会返回:
$myMongoDB->myCollection->find(array('type' => 'test', '$limit' => 10);
或者:
$myMongoDB->myCollection->find(array('$query' => array('type' => 'test'), '$limit' => 10);
任何人都可以帮我看看我做错了什么?
感谢您的帮助。
PS:对不起我的英语质量......
答案 0 :(得分:4)
我不知道你为什么要这样做:
$cursor = $collection->find(array('type' => 'test'));
$cursor->addOption( '$maxScan', 10 );
$maxScan
为$limit
,$orderby
为$sort
。
参考:http://docs.mongodb.org/manual/reference/operator/query-modifier/