1

I am trying to install the MongoDB bundle into Symfony2. I followed Symfony documentation.

My config.yml file is:

doctrine_mongodb:
connections:
    default:
        server: mongodb://localhost:27017
        options: {}
default_database: test_database
document_managers:
    default:
        auto_mapping: true

My autoload file is:

use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
$loader = require __DIR__.'/../vendor/autoload.php';

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
AnnotationDriver::registerAnnotationClasses();

return $loader;

The controller and the document/product files were exactly copied from the Symfony site (I only changed the name AcmeStoreBundle to MyTestBundle).

But when I attempt to insert data, I get the following error:

ClassNotFoundException: Attempted to load class "MongoId" from the global namespace in     
C:\wamp\www\MongoTest2\vendor\doctrine\mongodb-odm\lib\Doctrine\ODM\MongoDB\Id\AutoGenerator.php line 36.
Did you forget a use statement for this class?

(I cleared the cache and tried again)

Please help me to understand what's going wrong.

user1548055
  • 91
  • 2
  • 5
  • 1
    Have you installed the `mongo` PHP extension and added to the correct `php.ini`? Looks like a duplicate of: [ClassNotFoundException: Attempted to load class “Mongo” from… (with persist) symfony2](http://stackoverflow.com/questions/21025123/classnotfoundexception-attempted-to-load-class-mongo-from-with-persist-s). – Stennie Mar 24 '14 at 00:36
  • yeah thanks. The problem was solved when i installed the mongo db php extension correctly – user1548055 Apr 09 '14 at 05:17

1 Answers1

0

Install composer package alcaeus/mongo-php-adapter, because it has MongoId class. This also helped for me

Dr.X
  • 853
  • 9
  • 15