//connects to mongo
$collection = (new MongoDB\Client)->mfrmls->properties;
//takes array with data from array of objects
foreach ($obj as $k => $v){
//prints to make sure on the right record. this works fine
echo "object {$v['ListingId']} \n";
// creates a query to the mongo DB, which works fine, i have checked via var_dump
$cursor = $collection->find(['ListingId' => $v['ListingId']]);
//this for each will never print anything it just seems to be skipped.
//if i take it out of the nested foreach it works fine.
foreach($cursor as $document) {
echo "no no \n";
}
}
the results I get are :
object G4849756
object A4202291
object O5548422
object O5548513
object D5921405
which is clearly missing the second for loop echo.
just for reference. "$cursor" only gets called once the foreach statement runs, i guess this is just how mongoDB - PHP works.
var_dump($cursor);right after setting it to find out what's really in it. I'm also thinking maybe (I'd have to confirm) you may need to convert it from a obect to an array before you can useforeachon it. Not sure about that.