count()如果 Symfony-MongoDB-ODM 中的數據為空,則執(zhí)行odm 查詢(游標)不會返回“0”$query = $this->dm->createQueryBuilder('AppBundle:DocumentName');$count = $query->getQuery()->count();var$count總是返回大于零(“0”)的值。即使文檔中沒有數據注意:將游標轉換為數組會消耗更多內存,請原諒這種方法。
2 回答

梵蒂岡之花
TA貢獻1900條經驗 獲得超5個贊
您可以使用 AggregationBuilder。在你的 documentNameRepository 中試試這個代碼:
$qb = $this->createAggregationBuilder('Document\DocumentName');
$qb->count('nb_documents');
$results = $qb->execute();
return $results;
您可以在計數之前執(zhí)行 where 操作,如下所示:
$qb->match()
->field('field_name')
->equals(10);
您可以在計數之前執(zhí)行限制和跳過操作,如下所示:
$qb->skip(10)
->limit(100);
- 2 回答
- 0 關注
- 121 瀏覽
添加回答
舉報
0/150
提交
取消