我想了解聚合在mongo查詢中的工作原理。例如,我有文檔Product
和category
字段。我如何從每個類別中選擇最新添加的產品?Symfony Mongo查詢:select max
class Product {
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\Field(type="integer")
*/
protected $category;
這是我到目前爲止已經試過:
class ProductRepository extends DocumentRepository
{
public function lastProducts()
{
$qb = $this->createQueryBuilder();
$qb->max('id');
$qb->group(['category'], []);
return $qb->getQuery()->execute();
}
}
當我運行此查詢我得到Uncaught PHP Exception Doctrine\MongoDB\Exception\ResultException: "not code"
這個實體查詢生成器!這將不適用於mongo文件 – julie