I am using Symfony 2 with the Doctrine Mongodb ODM, and trying to create some indexes that work together with the fixtures I have already created and am trying to load with
php -f app/console doctrine:mongodb:fixtures:load
When I create indexes on my documents, loading the fixtures fails with
[Doctrine\ODM\MongoDB\MongoDBException]
Cannot execute unindexed queries on Updatemi\LibraryBundle\Document\UpdateTerm. Unindexed fields: update
Does ODM not generate the Indexes by itself?
After some research I found a solution to this problem.
Doctrine does not create the indexes automatically, after they are deleted, you have to do this yourself, using the command
This does not solve the problem for the fixtures, since they delete everything before they execute their code.
But there is a solution for this problem too!
At the start of your fixtures file, add a line that regenerates the indexes for you.
There is also a pull request on the doctrine_fixtures library to avoid deleting the indexes on fixture loading, so this fix hopefully is not necessary anymore.
https://github.com/doctrine/data-fixtures/pull/118