PHP 8.4.0 Beta 5 available for testing

L'extension MongoDB

Cette extension est développée au-dessus des bibliothèques » libmongoc et » libbson. Elle fournit une API minimale pour les fonctionnalités de base du pilote : commandes, requêtes, écritures, gestion de connection, et serialization BSON.

Les bibliothèques PHP côté utilisateur qui dépendent de cette extension peuvent fournir des API de plus haut niveau, telles que des constructeurs de requêtes, des méthodes d'aide pour les commandes individuelles, et GridFS. Les développeurs d'applications devraient envisager d'utiliser cette extension en conjonction avec la » bibliothèque MongoDB PHP, qui implémente les mêmes API de plus haut niveau que l'on trouve dans les pilotes MongoDB pour d'autres langages. Cette séparation des préoccupations permet à l'extension de se concentrer sur les fonctionnalités essentielles pour lesquelles une implémentation d'extension est primordiale pour les performances.

add a note

User Contributed Notes 3 notes

up
20
n dot vandermeij at mycademy dot com
7 years ago
*** ONLY FOR VERSIONS >= 1.2.0 ***

If you encounter the following error:

"PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mongodb.so'
- /usr/lib64/php/modules/mongodb.so: undefined symbol: php_json_serializable_ce in Unknown on line 0"

For a detailed explanation, please visit:

https://derickrethans.nl/undefined-symbol.html

TLDR: You need to load the mongodb.so extension after the json.so
extension

Special thanks to Derick Rethans for pointing this out!
up
4
mike at eastghost dot com
7 years ago
There is an adapter - so old MongoClient / MongoDB code will run on the new PHP7/Mongo mess

https://github.com/alcaeus/mongo-php-adapter
up
0
mike at eastghost dot com
6 years ago
PHP 'USERLAND' / HIGHER-LEVEL DRIVER IS HERE -- [url]https://github.com/mongodb/mongo-php-driver[/url]

In new driver, these fail:

(A) $count = $collection->find( $criteria )->count();

(B1) $cursor = $collection->find( $criteria );
(B2) $count = $cursor->count();

In new driver, result counting has become its own separate action, to be applied to the collection, not the cursor:

$count = $collection->count( $criteria );
$cursor = $collection->find( $criteria );

From jmikola 6 Jan 2016 ([url]https://github.com/mongodb/mongo-php-driver/issues/195 here[/url]):

"In the new driver, a Cursor object now represents the actual results of an executed command or query, whereas cursors in the legacy driver had a dual-nature (pre- or post-executed). The legacy MongoCursor::count() method actually invoked a count command with the same criteria; however, this meant it was entirely possible for the count command's calculation to differ from the actual query results, since they were not necessarily operating on the same result data.

"The userland library implements a count() method on the collection, which also takes filter criteria, and we'd rather encourage that so users understand that the operations are separate. If we do end up making Cursor countable in the userland library, we would use iterator_count() to provide an exact count on the results; however, this will also require us to cache the results so that users can rewind the cursor and iterate again (this was most recently discussed in PHPLIB-81). While the legacy driver would re-execute the query on a rewind, that's also not an option given the nature of a Cursor in the new driver.

"I realize this may come across as an inconvenience, but I believe the explicit API is a ultimately a step forward from the legacy driver, where many users might have been oblivious to what was actually happening under the hood. Feel free to follow up if you have additional questions.
To Top