doctrine / DoctrineMongoDBBundle

Integrates Doctrine MongoDB ODM with Symfony
http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
MIT License
379 stars 229 forks source link

"doctrine_mongodb" has no class #686

Closed kumargowdaa closed 3 years ago

kumargowdaa commented 3 years ago

The definition for "doctrine_mongodb" has no class. If you intended to inject this service dynamically at runtime , please mark it as synthetic=true.

kumargowdaa commented 3 years ago

@alcaeus please help on this. Thanks

franmomu commented 3 years ago

Hi @kumargowdaa, I'm not sure what you are trying to do there, can you show the full example or give some context?

In that code there is no doctrine_mongodb usage, only defining Doctrine\Bundle\MongoDBBundle as a service which is kind of strange because bundles are not supposed to be defined as a services, they are instantiated by Symfony.

kumargowdaa commented 3 years ago

@franmomu thanks for the reply.

This is the issue I am facing.

Using Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler with the legacy mongo extension is deprecated as of 3.4 and will be removed in 4.0. Use it with the mongodb/mongodb package and ext-mongodb instead.

Composer.json I haved added this mongodb bundles

Symfony version I have used. 3.4.38 "alcaeus/mongo-php-adapter": "^1.2", "doctrine/mongodb-odm": "1.3.7", "doctrine/mongodb-odm-bundle": "3.4.4",

And in config.yml I am using like this services: doctrine_mongodb: connections: default: server: "mongodb://%mongodb_connection_string%" options: {} default_database: %mongo_database% document_managers: default: auto_mapping: true session.handler.mongo: class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler arguments: ["@mongo_client", "%mongo.session.options%"]

franmomu commented 3 years ago

And in config.yml I am using like this services: doctrine_mongodb: connections: default: server: "mongodb://%mongodb_connection_string%" options: {} default_database: %mongo_database% document_managers: default: auto_mapping: true session.handler.mongo: class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler arguments: ["@mongo_client", "%mongo.session.options%"]

Can you please format this config.yml file? Apparently looks like doctrine_mongodb is defined in the services key, if it looks like something like this:

services:
  doctrine_mongodb:
     connections:
     #...

It's wrong, your configuration should look like: https://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/config.html#sample-configuration

To me, seems like you are mixing things here, what are you trying to do exactly? Looks like you want to store sessions using mongodb and for that you did this:

Composer.json I haved added this mongodb bundles

Symfony version I have used. 3.4.38 "alcaeus/mongo-php-adapter": "^1.2", "doctrine/mongodb-odm": "1.3.7", "doctrine/mongodb-odm-bundle": "3.4.4",

do you use the old ext-mongo driver? if not, you should install mongodb/mongodb and install ext-mongodb driver.

Once you do that, following this: https://symfony.com/doc/3.4/doctrine/mongodb_session_storage.html you only need to change the mongo client class to use \MongoDB\Client instead of MongoClient and there is no need of doctrine/mongodb-odm nor doctrine/mongodb-odm-bundle.

kumargowdaa commented 3 years ago

@franmomu thank you,

Yes I am using this to store sessions using mongodb.

Config.yml data I have posted throuh mobile so it's not formatted.

Please let me know which file I need to make this MongoDB\Client

Can u share me how I can install ext-mongodb. Plase share me the Composer command for install ext-mongodb

Thanks in advance

franmomu commented 3 years ago

ext-mongodb driver is a PHP extension, so it cannot be installed with composer, you can follow the instructions from:

https://github.com/mongodb/mongo-php-library#installation or https://www.php.net/manual/en/mongodb.installation.php

kumargowdaa commented 3 years ago

@franmomu ok thank you

Please let me know which file I need to make this MongoDB\Client

franmomu commented 3 years ago

Let's say you already have ext-mongodb extension installed and alsomongodb/mongodb in your composer, then you have to follow this documentation: https://symfony.com/doc/3.4/doctrine/mongodb_session_storage.html but where it says MongoClient, you would use \MongoDB\Client.

# app/config/config.yml
framework:
    session:
        # ...
        handler_id:  session.handler.mongo
        cookie_lifetime: 2592000 # optional, it is set to 30 days here
        gc_maxlifetime: 2592000 # optional, it is set to 30 days here

services:
    # ...
    mongo_client:
        class: \MongoDB\Client
        # if not using a username and password
        arguments: ['mongodb://%mongodb_host%:27017']
    session.handler.mongo:
        class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler
        arguments: ['@mongo_client', '%mongo.session.options%']
kumargowdaa commented 3 years ago

@franmomu thank you so much, its worked.

franmomu commented 3 years ago

You're very welcome, I'll close the issue then.

alcaeus commented 3 years ago

@kumargowdaa please be aware that we no longer support ODM 1.3 and the corresponding bundle versions. The issues you are facing are due to using outdated ODM versions which make it unnecessarily difficult to use the MongoDB session handler class.

Please update ODM to avoid such issues in the future, as we can't really help with getting them resolved.

kumargowdaa commented 3 years ago

@alcaeus thank you.

Could you please suggest which ODM version I should use for avoiding the issues??