Dans mon contrôleur, je suis aller chercher nombre limité d'objets (pour) comme ceci pagination:application Symfony2, MongoDB: Count tous les documents correspondant à des critères
$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 */
);
Maintenant, je tiens à obtenir le nombre total d'enregistrements qui répondent à la $criteria
.
je tentais de compter comme ceci:
$count = $repo->createQueryBuilder('MyDocument')
->count()->getQuery()->execute();
Mais il compte tous les records en matière de collecte. Comment puis-je appliquer $criteria
à cette requête de comptage?
J'ai besoin comme résultat natif MongoDB
db.MyDocument.find({'field2': "value1", 'field2': "value2"}).count()