Get ObjectId MongoDB via PHP
var_dump($object);
object(MongoDB\Model\BSONDocument)#36 (1) {
["storage":"ArrayObject":private]=>
array(8) {
["_id"]=>
object(MongoDB\BSON\ObjectID)#33 (1) {
["oid"]=>
string(24) "573e69e78fccd968aa066611"
}
["dummy"]=>
string(5) "mongo"
}
}
Failure
var_dump($object->_id->oid);
>>> null
var_dump($object->_id->{'oid'});
>>> null
var_dump($object->_id->{'$oid'});
>>> null
Success
$bson = \MongoDB\BSON\fromPHP($object);
$json = \MongoDB\BSON\toJSON($bson);
$result = json_decode($json, true);
var_dump($result['_id']['$oid']);
>>> string(24) "573e69e78fccd968aa066611"
exit;