MongoDB Extension for Yii 2
This extension provides the MongoDB integration for the Yii framework 2.0.
For license information check the LICENSE-file.
Documentation is at docs/guide/README.md.
Requirements ¶
This extension requires MongoDB PHP Extension version 1.20.1 or higher.
This extension requires MongoDB server version 4.0 or higher.
Installation ¶
[!IMPORTANT]
- The minimum required PHP version is PHP
7.4.- It works best with PHP
8.
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yiisoft/yii2-mongodb
or add
"yiisoft/yii2-mongodb": "~3.0.0"
to the require section of your composer.json.
Configuration ¶
To use this extension, simply add the following code in your application configuration:
return [
//....
'components' => [
'mongodb' => [
'class' => '\yii\mongodb\Connection',
'dsn' => 'mongodb://localhost:27017/mydatabase',
'options' => [
"username" => "Username",
"password" => "Password"
]
],
],
];
Known issues ¶
- yii\mongodb\Exception: no such command: 'group' with MongoDB server version 4.2 or higher.
Starting in version 4.2, MongoDB removes the group command (deprecated since version 3.4) and its mongo shell helper db.collection.group().
Class Reference
| Class | Description |
|---|---|
| yii\ |
ActiveFixture represents a fixture backed up by a MongoDB ActiveRecord class or a MongoDB collection. |
| yii\ |
ActiveQuery represents a Mongo query associated with an Active Record class. |
| yii\ |
ActiveRecord is the base class for classes representing Mongo documents in terms of objects. |
| yii\ |
BatchQueryResult represents a batch query from which you can retrieve data in batches. |
| yii\ |
Cache implements a cache application component by storing cached data in a MongoDB. |
| yii\ |
ClientSession represents a client session and Commands, queries, and write operations may then be associated the session. |
| yii\ |
Collection represents the Mongo collection information. |
| yii\ |
Command represents MongoDB statement such as command or query. |
| yii\ |
Connection represents a connection to a MongoDb server. |
| yii\ |
Database represents the MongoDB database information. |
| yii\ |
Exception represents an exception that is caused by some Mongo-related operations. |
| yii\ |
LogBuilder allows composition and escaping of the log entries. |
| yii\ |
Migration is the base class for representing a MongoDB migration. |
| yii\ |
Query represents Mongo "find" operation. |
| yii\ |
QueryBuilder builds a MongoDB command statements. |
| yii\ |
Session extends yii\ |
| yii\ |
In MongoDB, an operation on a single document is atomic. Because you can use embedded documents and arrays to capture relationships between data in a single document structure instead of normalizing across multiple documents and collections, this single-document atomicity obviates the need for multi-document transactions for many practical use cases. |
| yii\ |
Manages application MongoDB migrations. |
| yii\ |
ExplainAction provides EXPLAIN information for MongoDB queries |
| yii\ |
MongoDbPanel panel that collects and displays MongoDB queries performed. |
| yii\ |
ActiveQuery represents a Mongo query associated with an file Active Record class. |
| yii\ |
ActiveRecord is the base class for classes representing Mongo GridFS files in terms of objects. |
| yii\ |
Collection represents the Mongo GridFS collection information. |
| yii\ |
Cursor is a wrapper around \MongoDB\Driver\Cursor, which allows returning of the
record with yii\ |
| yii\ |
Download represents the GridFS download operation. |
| yii\ |
Query represents Mongo "find" operation for GridFS collection. |
| yii\ |
StreamWrapper provides stream wrapper for MongoDB GridFS, allowing file operations via regular PHP stream resources. |
| yii\ |
Upload represents the GridFS upload operation. |
| yii\ |
This generator will generate ActiveRecord class for the specified MongoDB collection. |
| yii\ |
MongoDbMessageSource extends yii\ |
| yii\ |
MongoDbTarget stores log messages in a MongoDB collection. |
| yii\ |
MongoDbManager represents an authorization manager that stores authorization information in MongoDB. |
| yii\ |
Permission is a special version of yii\ |
| yii\ |
Role is a special version of yii\ |
| yii\ |
MongoDateValidator is an enhanced version of yii\ |
| yii\ |
MongoIdValidator verifies if the attribute is a valid Mongo ID. |

