【发布时间】:2014-07-04 10:18:08
【问题描述】:
我将 Symfony2 与 DoctrineMongoDbBundle 一起使用
尝试使用new MongoId()时出现以下错误
ClassNotFoundException: Attempted to load class "MongoId" from namespace "..." in ...Controller.php line 64. Do you need to "use" it from another namespace?
我的控制器中的代码是
// connect
$m = $this->container->get('doctrine_mongodb.odm.default_connection');
// select a database
$db = $m->selectDatabase('db');
// select a collection (analogous to a relational database's table)
$collection = $db->createCollection('Entity');
// find everything in the collection
$entity = $collection->findOne(array('_id' => new MongoId($id)));
我可以在 ODM 中很好地使用 mongodb,如果我删除查询,它也可以正常工作,即
$entity = $collection->findOne();
感谢任何帮助,谢谢
【问题讨论】:
标签: mongodb symfony doctrine-orm mongodb-query doctrine-odm