forEach mongodb PHP -
is there efficient way use foreach in mongodb php, problem able add new row csv file every element in result array. 1 of possible solution use
$data mongo cursor
$records = iterator_to_array($data); $file = fopen("contacts.csv","w"); foreach ($records $record){ fputcsv($file,$record); }
but, loading entire data memory not scalable option problem, data can huge.is there better alternative way able use foreach. how use foreach mongo php
$file = fopen("contacts.csv","w"); foreach ($data $record){ $contact = iterator_to_array($record); fputcsv($file,$contact); }
this solution works $data remains cursor , iterator_to_array() inside loop converts individual record array placed in csv file.
Comments
Post a Comment