Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony2应用程序,MongoDB:统计所有符合条件的记录_Mongodb_Symfony_Doctrine Orm_Mongodb Query - Fatal编程技术网

Symfony2应用程序,MongoDB:统计所有符合条件的记录

Symfony2应用程序,MongoDB:统计所有符合条件的记录,mongodb,symfony,doctrine-orm,mongodb-query,Mongodb,Symfony,Doctrine Orm,Mongodb Query,在我的控制器中,我获取有限数量的对象(用于分页),如下所示: $dm = $this->get('doctrine_mongodb'); $repo = $dm->getRepository('AcmeMyBundle:MyDocument'); $criteria = array( 'field1' => 'value1', 'field1' => 'value1', ); $l

在我的控制器中,我获取有限数量的对象(用于分页),如下所示:

    $dm   = $this->get('doctrine_mongodb');
    $repo = $dm->getRepository('AcmeMyBundle:MyDocument');

    $criteria = array(
        'field1'    => 'value1',
        'field1'    => 'value1',
    );

    $logs = $repo->findBy(
        $criteria,                      /* criteria */
        array($field => $direction),    /* sort */
        $limit,                         /* limit */
        (($page-1)*$limit)?:null        /* skip */
    );
$count = $repo->createQueryBuilder('MyDocument')
    ->count()->getQuery()->execute();
    $countQuery = $repo
        ->createQueryBuilder('MyDocument')
        ->requireIndexes(false)
        ;

    foreach(array_filter($criteria) as $field=>$value){
        $countQuery->field($field)->equals($value);
    }

    $count = $countQuery->count()->getQuery()->execute();
现在,我想获得满足
$标准的记录总数

我试着这样数数:

    $dm   = $this->get('doctrine_mongodb');
    $repo = $dm->getRepository('AcmeMyBundle:MyDocument');

    $criteria = array(
        'field1'    => 'value1',
        'field1'    => 'value1',
    );

    $logs = $repo->findBy(
        $criteria,                      /* criteria */
        array($field => $direction),    /* sort */
        $limit,                         /* limit */
        (($page-1)*$limit)?:null        /* skip */
    );
$count = $repo->createQueryBuilder('MyDocument')
    ->count()->getQuery()->execute();
    $countQuery = $repo
        ->createQueryBuilder('MyDocument')
        ->requireIndexes(false)
        ;

    foreach(array_filter($criteria) as $field=>$value){
        $countQuery->field($field)->equals($value);
    }

    $count = $countQuery->count()->getQuery()->execute();
但它统计收集的所有记录。如何将
$criteria
应用于该计数查询

我需要将结果作为本机
MongoDB
db.MyDocument.find({'field2':'value1','field2':'value2})。count()
这样做:

    $dm   = $this->get('doctrine_mongodb');
    $repo = $dm->getRepository('AcmeMyBundle:MyDocument');

    $criteria = array(
        'field1'    => 'value1',
        'field1'    => 'value1',
    );

    $logs = $repo->findBy(
        $criteria,                      /* criteria */
        array($field => $direction),    /* sort */
        $limit,                         /* limit */
        (($page-1)*$limit)?:null        /* skip */
    );
$count = $repo->createQueryBuilder('MyDocument')
    ->count()->getQuery()->execute();
    $countQuery = $repo
        ->createQueryBuilder('MyDocument')
        ->requireIndexes(false)
        ;

    foreach(array_filter($criteria) as $field=>$value){
        $countQuery->field($field)->equals($value);
    }

    $count = $countQuery->count()->getQuery()->execute();