Altas Test Database Beginner's Terrible Experience

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://', [], ['server$
$client = new MongoDB\Client('mongodb+srv://');
$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 after $database= $client->test:

string(4) “test”
object(MongoDB\Driver\Manager)#2 (2) {
string(88) “mongodb+srv:/”
array(0) {
object(MongoDB\Driver\ReadConcern)#8 (0) {
object(MongoDB\Driver\ReadPreference)#9 (1) {
string(7) “primary”
array(3) {
string(23) “MongoDB\Model\BSONArray”
string(26) “MongoDB\Model\BSONDocument”
string(26) “MongoDB\Model\BSONDocument”
object(MongoDB\Driver\WriteConcern)#10 (1) {
string(8) “majority”

No collections returned???

May be there is no collection in your database. Can you connect with Compass and share a screenshot of the collections you have?

It looks like there is a discrepancy between the code

and the following output (looks like a missing /)

May be the missing slash was removed while redacting the URI.

You appear to be connecting to your test database. Do you have any collections in that database?

I think your code will probably work if you connect to a database with collections.

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?

Glad you were able to connect!

I’m not quite following this however:

In the documentation it says:

The executable is called MongoDB Compass . The installer installs it under the Applications folder:

/Applications/MongoDB\\ Compass

The app is indeed called “MongoDB Compass” and it is in the /Applications/ folder (as the MongoDB .

MongoDB\ == MongoDB as the backslash is to escape the space.

Seems like everything is correct?