[MODM-173] Change the name of the collection dynamic Created: 27/Jun/13  Updated: 27/Jun/13

Status: Open
Project: Doctrine MongoDB ODM
Component/s: Collections
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: Daniel Gafitescu Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: None


I have to create collection for users per each day they register so if I have 5 users and 2 register on 2013-03-02 and 3 have register on 2013-03-03 I will have 2 collections

The user is declare in a YML file with no collection specified

In the project I do an import via CLI something like this

foreach($arUsers as $key => $arUser)

    $collection_name = 'day_' . $arUser['date'];

    $user = new User();

    /* Change the collection name to be dynamic  */
    $OdmMetaData = $documentManager->getClassMetaData(get_class($user));



    // ....

    // should save the user to `'day_' . $arUser['date']`

Problem is that when I look in the mongoDB I see only one collection with name "day_2013-03-03" which is the last date , if I set the


after the foreach end statement which I should it save all in the first collection "03-02".

Comment by Marco Pivetta [ 27/Jun/13 ]

I personally don't think that's an use case to be handled in the ODM.

The problem is that class metadata properties are not constantly accessed, but instead cached locally in various components for performance reasons.

A fix for this would be to explicitly deny modification of metadata after it was returned by the metadata factory (after "onLoadMetadata" events).

Comment by Daniel Gafitescu [ 27/Jun/13 ]

Reinitialize the DoctrineManager at every group of document did the trick but it's just not beautiful code.
In a perfect world it would be nice to have a method setCollectionName on a object. But then again Doctrine is a open source project and all that work on the project are doing this on their own time and I thank you for that.

Generated at Thu Oct 08 23:29:00 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.