john Smith john Smith - 7 months ago 19
PHP Question

Doctrine2 ODM Limit dont work / mongodb

i´m trying to skip and limit results but i dont even get it to work to limit results.

heres my code

$limit=5;
$fooQueryBuilder = $this->mongo->getManager()->createQueryBuilder('CustomCoreBundle:Foo');
$foos=$fooQueryBuilder->limit($limit)->getQuery()->execute();

var_dump(count($foos));
exit;


and the var_dump returns

int(321235)


and thats equal to all entities in database, what am i dooing wrong ?

$this->mongo->getManager()


is instance of

Doctrine\ODM\MongoDB\DocumentManager


and the builder is instance of

Doctrine\ODM\MongoDB\Query\Builder"


i just dont understand whats wrong, thanks for any hint

Answer

so i found out the answer myself

it is working !

and i learned:

when you count() a cursor, no matter what query, it returns the amount of all entities in database.

so my check to count the cursor to see if the limit is working was simply wrong