Symfony 4 and Doctrine Mongo DB

Mert Sevinc
4 min readMar 28, 2018

It’s hard to keep up with all the crazy developments in the software world. You start to learn PHP, then you discover there is Zend Framework and you switch to that, then you learn about Symfony, which is far superior than Zend, and you start learning that but then you learn there is a newer version of Symfony but for some crazy reason things have changed significantly in that. Come on :-) Stop changing things…

You know you could use Doctrine perfectly with Symfony 3 but now it does not seem to work with Symfony 4 and you start to search the whole world wide web to figure out what could be the problem. Obviously, what’s missing in open source world is always the documentation :-)

Anyways…. I wanted to create a new project with Symfony 4 and Doctrine MongoDB the other day. Unfortunately, doctorine’s documentation was outdated. After spending some time, I managed to make those two work together. While it is still fresh in my mind, I wanted to share it with you so that I can save your precious time.

Ok so what we need to make Doctrine Mongo and Symfony 4 are the following packages:

"alcaeus/mongo-php-adapter"
"doctrine/mongodb-odm-bundle"

Alcaeus is still a requirement if you are on PHP 7 like I do.

After you install these packages via composer, it’s time to make some configuration, which was the most unknown and difficult part for me.

--

--