MongoDBの最新バージョンであるMongoDB\Driver \ Managerの場合、次の動作コードを検討することができます。
try {
$DB_CONNECTION_STRING="mongodb://YourCredentials";
require '../../vendor/autoload.php';
$manager = new MongoDB\Driver\Manager( $DB_CONNECTION_STRING );
$filter = ['_id' => new MongoDB\BSON\ObjectID( '5bdf54e6d722dc000f0aa6c2' )];
$options = [];
$query = new MongoDB\Driver\Query($filter, $options);
$docs = $manager->executeQuery('YourDbName.YourCollectionName', $query);
}
catch (MongoDB\Driver\Exception\Exception $e) {
$filename = basename(__FILE__);
echo "The $filename script has experienced an error.\n";
echo "It failed with the following exception:\n";
echo "Exception:", $e->getMessage(), "\n";
}
テスト目的:
foreach ($docs as $doc) {
print_r($doc);
//or you can: echo "$doc->item $row->qty $row->status<br />";
}