$client = new MongoDB\Client("mongodb://localhost:27017"); $collection = $client->myDatabase->myCollection; $cursor = $collection->find();
$client = new MongoDB\Client("mongodb://localhost:27017"); $collection = $client->myDatabase->myCollection; $result = $collection->findOne(["_id" => new MongoDB\BSON\ObjectID("5d8f16429bb6d70ae6a682f6")]);This example uses the selectCollection method to retrieve a single document from the "myCollection" collection in the "myDatabase" database. The document with the specified object ID is retrieved and stored in the $result variable. Package library: - MongoDB PHP library