Preformatted textSpent all day wrestling with poor documentation in as of now failed attempt to test MongdoDB for an application. Finally appear to be able to establish a connection with Atlas sample database from external Linux server with latest PHP Library and Extension, yet listCollections call yields empty response.
Complete code:
#Following two lines commented out since call to ServerApi results in error: "Fatal error: Uncaught Error: Class 'ServerApi' not found i$
#$serverApi = new ServerApi(ServerApi::V1);
#$client = new MongoDB\Client('mongodb+srv://username:password@cluster0.irus4oq.mongodb.net/?retryWrites=true&w=majority', [], ['server$
$client = new MongoDB\Client('mongodb+srv://username:password@cluster0.irus4oq.mongodb.net/?retryWrites=true&w=majority');
$database = $client->test;
$cursor = $database->command(['ping' => 1]);
$cursor = $database->command(['listCollections' => 1]);
foreach ($cursor as $collection) {
echo $collection['name'], "\n";
}
foreach ($database->listCollections() as $collectionInfo) {
var_dump($collectionInfo);
}
Have been able to connect and access now that collectoins are in database.
Still surprised by basic error in documentation. For instance, the documentation describes Mongo Compass on the Mac as being installed in /Applications/MongoDB while it is actually installed as /Applications/MongoDB Compass. Small difference, but confusing to beginners. Why can’t the company keep documentation current and accurate?