doushui3216 2014-06-17 21:11
浏览 34
已采纳

Doctrine2 ODM限制不起作用/ mongodb

I'm trying to skip and limit results, but I don't even get it to limit the results.

here's my code

    $limit=5;
    $fooQueryBuilder = $this->mongo->getManager()->createQueryBuilder('CustomCoreBundle:Foo');
    $foos=$fooQueryBuilder->limit($limit)->getQuery()->execute();

    var_dump(count($foos));
    exit;

and the var_dump returns

int(321235)

and that's equal to all entities in the database, what am I doing wrong ?

$this->mongo->getManager() 

is instance of

Doctrine\ODM\MongoDB\DocumentManager

and the builder is instance of

Doctrine\ODM\MongoDB\Query\Builder"

I just don't understand what's wrong, thanks for any hint

  • 写回答

2条回答 默认 最新

  • dongzhentiao2326 2014-06-18 06:52
    关注

    So, I found out the answer myself

    it is working !
    

    and I learned:

    when you count() a cursor, no matter what the query, it returns the amount of all entities in database.

    So my check to count the cursor to see if the limit is working was simply wrong

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 镍氢电池充电器设计实物使用原理
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?