When I use a mongo DB cursor in php:
$Cursor = \MyDocument::find();
foreach ($Cursor as $Document)
$Document->doSomething();
Is there then only left the last $Document in the memory or do I have to remove the built documents from the cursor object?
Basically, only
$Documentwill be in memory which is the current one inside theforeachiteration.As long as you’re not running into actual memory problems, I would leave it with this simplified description.
See as well: MongoDB – Why should I use a cursor instead of iterator_to_array (in PHP).
The MongoCursor class documentation explains this as well.