MongoDB driver
Unlike the mongo extension, this extension supports both PHP and HHVM and is developed atop the » libmongoc and » libbson libraries. It provides a minimal API for core driver functionality: commands, queries, writes, connection management, and BSON serialization.
Userland PHP libraries that depend on this extension may provide higher level APIs, such as query builders, individual command helper methods, and GridFS. Application developers should consider using this extension in conjunction with the » MongoDB PHP library, which implements the same higher level APIs found in MongoDB drivers for other languages. This separation of concerns allows the driver to focus on essential features for which an extension implementation is paramount for performance.
- Установка и настройка
- Tutorials
- Driver Architecture and Internals — Explains the driver architecure, and special features
- Architecture — Architecture Overview
- Persisting Data — Serialisation and deserialisation of PHP variables into MongoDB
- Security
- MongoDB\Driver — MongoDB driver classes
- MongoDB\Driver\Manager — The MongoDB\Driver\Manager class
- MongoDB\Driver\Command — The MongoDB\Driver\Command class
- MongoDB\Driver\Query — The MongoDB\Driver\Query class
- MongoDB\Driver\BulkWrite — The MongoDB\Driver\BulkWrite class
- MongoDB\Driver\WriteConcern — The MongoDB\Driver\WriteConcern class
- MongoDB\Driver\ReadPreference — The MongoDB\Driver\ReadPreference class
- MongoDB\Driver\ReadConcern — The MongoDB\Driver\ReadConcern class
- MongoDB\Driver\Cursor — The MongoDB\Driver\Cursor class
- MongoDB\Driver\CursorId — The MongoDB\Driver\CursorId class
- MongoDB\Driver\Server — The MongoDB\Driver\Server class
- MongoDB\Driver\WriteConcernError — The MongoDB\Driver\WriteConcernError class
- MongoDB\Driver\WriteError — The MongoDB\Driver\WriteError class
- MongoDB\Driver\WriteResult — The MongoDB\Driver\WriteResult class
- MongoDB\BSON — BSON type classes and serialization functions
- Функции
- MongoDB\BSON\Binary — The MongoDB\BSON\Binary class
- MongoDB\BSON\Javascript — The MongoDB\BSON\Javascript class
- MongoDB\BSON\MaxKey — The MongoDB\BSON\MaxKey class
- MongoDB\BSON\MinKey — The MongoDB\BSON\MinKey class
- MongoDB\BSON\ObjectID — The MongoDB\BSON\ObjectID class
- MongoDB\BSON\Regex — The MongoDB\BSON\Regex class
- MongoDB\BSON\Timestamp — The MongoDB\BSON\Timestamp class
- MongoDB\BSON\UTCDateTime — The MongoDB\BSON\UTCDateTime class
- MongoDB\BSON\Type — The MongoDB\BSON\Type interface
- MongoDB\BSON\Persistable — The MongoDB\BSON\Persistable interface
- MongoDB\BSON\Serializable — The MongoDB\BSON\Serializable interface
- MongoDB\BSON\Unserializable — The MongoDB\BSON\Unserializable interface
- MongoDB\Driver\Exception — Exception classes
- MongoDB\Driver\Exception\AuthenticationException — The MongoDB\Driver\Exception\AuthenticationException class
- MongoDB\Driver\Exception\BulkWriteException — The MongoDB\Driver\Exception\BulkWriteException class
- MongoDB\Driver\Exception\ConnectionException — The MongoDB\Driver\Exception\ConnectionException class
- MongoDB\Driver\Exception\ConnectionTimeoutException — The MongoDB\Driver\Exception\ConnectionTimeoutException class
- MongoDB\Driver\Exception\Exception — The MongoDB\Driver\Exception\Exception interface
- MongoDB\Driver\Exception\ExecutionTimeoutException — The MongoDB\Driver\Exception\ExecutionTimeoutException class
- MongoDB\Driver\Exception\InvalidArgumentException — The MongoDB\Driver\Exception\InvalidArgumentException class
- MongoDB\Driver\Exception\LogicException — The MongoDB\Driver\Exception\LogicException class
- MongoDB\Driver\Exception\RuntimeException — The MongoDB\Driver\Exception\RuntimeException class
- MongoDB\Driver\Exception\SSLConnectionException — The MongoDB\Driver\Exception\SSLConnectionException class
- MongoDB\Driver\Exception\UnexpectedValueException — The MongoDB\Driver\Exception\UnexpectedValueException class
- MongoDB\Driver\Exception\WriteException — The MongoDB\Driver\Exception\WriteException class
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- CUBRID
- DB++
- dBase
- filePro
- Firebird/InterBase
- FrontBase
- IBM DB2, Cloudscape and Apache Derby
- Informix
- Ingres DBMS, EDBC, and Enterprise Access Gateways
- MaxDB
- MongoDB
- MongoDB
- mSQL
- Microsoft SQL Server
- MySQL Drivers and Plugins
- Oracle OCI8
- Paradox File Access
- PostgreSQL
- SQLite
- SQLite3
- Microsoft SQL Server Driver for PHP
- Sybase
- tokyo_tyrant
Коментарии
*** 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!
There is an adapter - so old MongoClient / MongoDB code will run on the new PHP7/Mongo mess
https://github.com/alcaeus/mongo-php-adapter
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.