1

I'm using MongoDB Doctrine ODM on a Symfony 2 project. In the documents classes the mapping metadata are specified by annotations. For example:

    /**
     * @MongoDB\Document(collection="statistiche")
     */

The collection name in this way is hardcoded. I want to have dynamical collection name parameter, that can be readed from global parameters.yml Symfony file (and, consequently, can be configured by user). How can I perform this goal? Thanks.

DanieleVT
  • 131
  • 6

1 Answers1

0

Then don't use the annotation but use yaml from your metadata definition.

Documentation and Example

But be aware that every metadata definition (be it per annotation, yaml or whateever) usually is loaded only once and cached for performance reasons in production.

That means that you usually have to clear your cache to use an updated metadata definition.

Another issue to consider is when you rename an already existing document/attribute. This might require some migration activities to avoid unexpected behaviour.

LBA
  • 3,859
  • 2
  • 21
  • 60