PHP Library 1.15 seems to include outdated tutorials (e.g. references removed geoNear command)

The tutorial titled “” on [this page](at Execute Database Commands — PHP Library Manual upcoming) includes the following suggested code:

$cursor = $database->command([
    'geoNear' => 'restos',
    'near' => [
        'type' => 'Point',
        'coordinates' => [-74.0, 40.0],
    ],
    'spherical' => 'true',
    'num' => 3,
]);

Which results in the following fatal error:

Fatal error: Uncaught MongoDB\Driver\Exception\CommandException: no such command: ‘geoNear’ in…

Apparrently support for geoNear has been gone since MongoDB version 4.2 as per MongoDB Manual 6.0 .

What am I missing?

There are several other deprecated references in Atlas start-up guide and tutorials for use of PHP library. In fact, PHP library references are completely removed from this seminal “connect to your cluster” tutorial. Only access options described are for: PyMongo Driver, Node.js Driver, MongoDB Shell, and Compass.

Documentation issues can be reported here.

You might also fill out the MongoDB Documentation Survey and maybe point them at this problem if it allows such.

[NOT ALLOW URLS SO HAVE REMOVED FORM BELOW]

Thanks. Have created a documentation issue ticket illustrating the following sloppiness. Consider myself an advanced programmer, though completely new to MongdoDB. Spent an entire day trying to configure PHP script access to Atlas test environment. Not successful. Documentation deficiencies not helping. Very surprised documentation not better; Mongo is a pretty mature company at this point. For example:

  1. First one to show carelessness which is indicative of deeper problems:

On reference page MongoDBDatabase-command :

$cursor = $database->command([‘listCollections’ => 1]);
var_dump($c->toArray());

$c->toArray() should be $cursor->toArray()

  1. On same page:

Function template is:

function command($command, array $options = ): MongoDB\Driver\Cursor

Yet actual and example call via object class is:

$cursor = $database->command([‘ping’ => 1]);

The passed parameter is an array, though the template displays a string followed by an array. Further the value in the array (“1”) is not explained.

  1. On same page:

The exampled listCollections commands executed via command function appears to be comparable to the listCollections() function] (at MongoDBDatabase-listCollections). The similarities and differences between the two calling methods are not described for beginners.

  1. “Connecting to a cluster with PHP Driver” page Cloud: MongoDB Cloud contains tutorial code for that triggers error:

$serverApi = new ServerApi(ServerApi::V1);

Triggers error: “Fatal error: Uncaught Error: Class ‘ServerApi’ not found in…”

You’ll get no argument from me, @G_Chase .
Generally in the programming field one is finding PHP to attract less attention than it once did.
I work with legacy IBM systems (which are in fact quite modern, they have all the goodies) where PHP has a big presence.
All I can say is that I do use PHP with MongoDB and it works very well, even if the docs have problems.

Anyway, here’s a silly little example, if this helps.

<?php
require_once 'vendor/autoload.php';
$mongodb_client = new MongoDB\Client('mongodb+srv://myid:mypassword@cluster0-xxxxx.mongodb.net/test?retryWrites=true&w=majority');
$db = $mongodb_client->selectDatabase('admin');
$cursor = $db->command(["serverStatus" => 1]);
var_dump($cursor->toArray()[0]);
?>

Of course, you have to change id, password, and cluster name for it work.

I assume the subject of this thread is a typo, as 1.15.0 is the most recent PHPLIB release.

I followed up on all of the issues raised in PHPLIB-1055 but I’ll address some other points below.

In fact, PHP library references are completely removed from this seminal “connect to your cluster” tutorial. Only access options described are for: PyMongo Driver, Node.js Driver, MongoDB Shell, and Compass.

This wasn’t mentioned in PHPLIB-1055, so I’ll field this here.

For language-specific examples within other product manuals (e.g. Atlas, MongoDB server), drivers teams generally get a produce example code, which then gets added to our test suite (for ongoing test coverage) and parsed by other teams to incorporate into their own docs. One example of this is PHPLIB-350 and the DocumentationExamplesTest.php file in the PHPLIB repository.

I’m not familiar with that page but it appears to be maintained by the Atlas team. I don’t recall ever seeing a ticket related to the Atlas connection examples you referenced above, but I’ll follow up internally with that team to ask why only a subset of drivers are included (PHP is not the only one missing).

There are several other deprecated references in Atlas start-up guide and tutorials for use of PHP library.

I assume this is referring to something other than the missing connection examples above. Can you share references to these docs pages so I can look into this further?

Documentation issues can be reported here.

Slight correction. Most MongoDB manual pages should have a “Share Feedback” widget in the bottom right corner. If so, that’s the preferred way to report documentation issues since it will spawn a JIRA ticket with the correct template and context (also without requiring the user to have a JIRA account). In the absence of that, creating a DOCS ticket directly will still get the attention of the right people and can be triaged or moved to other teams as needed.

PHP driver docs are handled entirely by the driver engineers, so reporting issues directly in either the PHPLIB or PHPC (for extension docs on PHP.net) is preferable.

In @G_Chase’s case, one of the issues pertained to code examples within the Atlas UI itself. Since that’s a separate team, I created an internal ticket for them to look into that and cross-referenced it with PHPLIB-1055 for context.

1 Like

Thank you, have reprorted doc error as open sisue. And thank you @Jack_Woehr for confirmation of general php doc deficiencies.

As discussed above, the geonear command example is still provided in tutorial, but the command no longer exists. Has it been replaced by “nearSphere”? I have been completely unable to find a PHP example of searching the sample Atlas collections by lat/long. Can you provide a PHP example of applying nearShpere to the sample collection: sample_geospatial.shipwrecks?

Thanks

the geonear command example is still provided in tutorial

mongodb/mongo-php-library#1024 is the corresponding PR for PHPLIB-1055. It has yet to be merged and published, which is why the geoNear example is still visible in the Executing Database Commands tutorial.

Has it been replaced by “nearSphere”?

Since geoNear was deprecated and removed in MongoDB 4.0 and 4.2, respectively, I searched up the final copies of its documentation in the server manual:

The suggested alternatives to the geoNear command are as follows:

Note that the $geoNear stage and $nearSphere/$near query operators all return documents in a sorted order (nearest to farthest).

Can you provide a PHP example of applying nearShpere

I don’t have any PHP example handy, but the above operators would be no different than using any other aggregation stages or query operators in the PHP driver. The BSON documents in the server manual would just need to be translated to a PHP structure (e.g. associative array).

1 Like

Thanks for clarifying the preferred procedurie, @jmikola