I'm starting out with Symfony and doctrine/mongodb. I'm trying to do an aggregation query, but I get
Attempted to call an undefined method named "createAggregationBuilder" of class "Doctrine\ODM\MongoDB\DocumentManager"
with something like this:
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class TestController extends Controller
{
/**
* @Route("/test", name="test")
*/
public function testAction(Request $request) {
$builder = $this->get('doctrine_mongodb')
->getManager()
->createAggregationQuery('AppBundle:Test');
var_dump($builder);
}
}
I'm quite frustrated now, since every documentation or stackoverflow questions and answers start with
$dm->createAggregationQuery();
and I can't find out what $dm
stands for in this case.
I'd really appreciate some help here.
UPDATE
I was looking around in the doctrine/mongodb-odm source code and I found that my version is missing the createAggregationBuilder
function from both the DocumentRepository.php
and the DocumentManager.php
file (both located in /vendor/doctrine/mongodb-odm/lib/Doctrine/MongoDB
folder.
How can this be?
I mean composer says that I have version 1.1.6, which is the latest release and on the git repo I can cleary see these methods (DocumentRepository.php, DocumentManager.php)
$dm
is probably a DocumentManager instance in most examples. – ccKep$builder = $dm->createAggregationBuilder(\Documents\User::class);
So how can I instantiate that DocumentManager class? I thougth that was what$this->get('doctrine_mongodb')->getManager()
did. It's probably me, who doesn't know enough of the doctrine way. – mywebstuff.hq$dm = $this->get('doctrine_mongodb')->getManager();
sounds about right. What does it return? – ccKep