简体   繁体   中英

Symfony2 mongodb installation

I've been following this with a fresh install of symfony2 and everything goes fine until I hit the step where it says

php app/console doctrine:mongodb:generate:documents AcmeStoreBundle

which then gets me the error

Bundle AcmeStoreBundle does not contain any mapped documents. Did you maybe forget to define a mapping configuration?  

I've followed the guide exactly other than in config.yml, where I had a custom URI connection string since I turned on auth. I don't believe this is the problem, but I'll post it anyways.

doctrine_mongodb:
connections:
    default:
        server: mongodb://root:password@localhost:27017
        options: {}
default_database: admin
document_managers:
    default:
        auto_mapping: true

Aha, I've had this issue before. Keep Calm, you probably forgot to put < ?php

I think you forgot the following step:

Add Mapping Information ( http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html#add-mapping-information )

When I do not do that step, I am getting the same error as you. It's either you didn't do it, or you did that step wrong, so I suggest you have a look at that again.

So to be clear: DoctrineMongoDBBundle looks for a package called Document inside the bundle. If your entities are stored somewhere else, eg in an Entity package you will get this error.

The solution in that case is to point doctrine to the right folder like so:

doctrine_mongodb:
    connections:
        default:
            server: mongodb://localhost:27017
            options: {}
    default_database: test_database
    document_managers:
        default:
            auto_mapping: true
            mappings:
                AppBundle:
                    type: annotation
                    dir: Entity
                    prefix: 'AppBundle\Entity'

I solved this by adding an entry to my configs.yml file. My document had all the annotations needed, but this was also needed.

## config.yml

# MongoDB Configuration
doctrine_mongodb:
    document_managers:
        default:
            connection: default
            database: %database_name%
            retry_connect: %database_retry%
            retry_query: %database_retry%
            mappings:
                # Mapped bundles go here
                EccSpecialBundle: ~
                EccSuperBundle: ~

I realize this is not the solution to your problem, but I've run into this one a couple times now, so someone else might as well!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM