2

I'm using DoctrineMongoDBBundle, normally i put the documents into the MyBundle/Document directory and works fine but i want change to MyBundle/Model

after move my documents to new namespace i get a error message

[Exception] 
You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles...

currently i'm using annotations for set the configuration, i dont want use xml or yml. this is the current config, how i can achieve this?

# app/config/config.yml
doctrine_mongodb:
    connections:
        default:
            server: mongodb://localhost:27017
            options: {}
    default_database: "%database_name%"
    document_managers:
        default:
            auto_mapping: true
rkmax
  • 17,633
  • 23
  • 91
  • 176

1 Answers1

2

Assuming your document is Acme/Model/Invoice.

You can adjust the mapping like this:

doctrine:
  odm:
    # ...
    mappings:
      Acme:
        type: annotation
        is_bundle: false
        dir: %kernel.root_dir%/../src/Acme/Model
        prefix: Acme\Model
        alias: MyDocuments

Now use the the mapping like this:

$documentManager->getRepository('MyDocuments:Invoice');

If you want to keep the document inside a bundle ...

... just use the bundle's name i.e. AcmeDemoBundle instead of Acme as the mapping-name, set is_bundle to true and the dir option will be seen as relative to the bundle's root directory.

More information on the mapping options can be found in the documentation chapter DoctrineBundle Configuration#Mapping Information.

More information on how to store documents out of bundles can be found in this blog post.

The procedure is the same for Doctrine ORM btw.

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130