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