我的数据库中有大约 60k 个文档,我无法查询它们。我能够成功检索它们的唯一方法是使用 hydrate(false) 选项。
我都试过了:
$dm = $this->get('doctrine_mongodb')->getManager();
$qb = $dm->createQueryBuilder('BConwayWebsiteBundle:Business')
->eagerCursor(true);
$query = $qb->getQuery();
$results = $query->execute();
和
$dm = $this->get('doctrine_mongodb')->getManager();
$qb = $dm->createQueryBuilder('BConwayWebsiteBundle:Business');
$query = $qb->getQuery();
$results = $query->execute();
如果我转储 $results->isInitialized() 它是错误的。我相信那是因为那时我还没有使用它。我尝试做的任何访问都会导致内存问题。甚至像 $results->count() 这样基本的东西。
[2013-10-01 23:54:55] doctrine.INFO: MongoDB query: {"find":true,"query":[],"fields":[],"db":"ClosedForTheHoliday","collection":"businesses"} [] []
[2013-10-01 23:54:55] doctrine.INFO: MongoDB query: {"limit":true,"limitNum":null,"query":[],"fields":[]} [] []
[2013-10-01 23:54:55] doctrine.INFO: MongoDB query: {"skip":true,"skipNum":null,"query":[],"fields":[]} [] []
[2013-10-01 23:54:55] doctrine.INFO: MongoDB query: {"sort":true,"sortFields":[],"query":[],"fields":[]} [] []
[2013-10-01 23:54:56] emergency.EMERGENCY: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) {"type":1,"file":"/media/sf_sites/cfth_com/vendor/doctrine/mongodb/lib/Doctrine/MongoDB/Cursor.php","line":237} []
更新:如果我将结果限制为 2000,它会起作用。此外,如果我只选择查询后要使用的两个字段,我可以将其限制为 15000 并成功。当我将其限制为 2000 时,开发调试栏显示查询使用了 120MB 内存。我需要能够遍历所有结果,并且不能分页。似乎没有 100MB+ 的查询应该是可能的......