PHPackages                             yiisoft/yii2-mongodb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. yiisoft/yii2-mongodb

ActiveYii2-extension[Framework](/categories/framework)

yiisoft/yii2-mongodb
====================

MongoDB extension for the Yii framework

3.0.4(7mo ago)3312.1M—5.1%191[5 issues](https://github.com/yiisoft/yii2-mongodb/issues)[12 PRs](https://github.com/yiisoft/yii2-mongodb/pulls)20BSD-3-ClausePHPCI passing

Since Apr 13Pushed 3mo ago45 watchersCompare

[ Source](https://github.com/yiisoft/yii2-mongodb)[ Packagist](https://packagist.org/packages/yiisoft/yii2-mongodb)[ GitHub Sponsors](https://github.com/yiisoft)[ Fund](https://opencollective.com/yiisoft)[ RSS](/packages/yiisoft-yii2-mongodb/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (28)Used By (20)

 [ ![](https://camo.githubusercontent.com/b03378e6893070fd365e1c95eb6553933577a14cbf0837c31b16bb6f25783efb/68747470733a2f2f7765626173736574732e6d6f6e676f64622e636f6d2f5f636f6d5f6173736574732f636d732f6d6f6e676f64622d6c6f676f2d7267622d6a36773237316731786e2e6a7067) ](https://www.mongodb.com/)

MongoDB Extension for Yii 2
===========================

[](#mongodb-extension-for-yii-2)

This extension provides the [MongoDB](https://www.mongodb.com/) integration for the [Yii framework 2.0](https://www.yiiframework.com).

For license information check the [LICENSE](LICENSE.md)-file.

Documentation is at [docs/guide/README.md](docs/guide/README.md).

[![Latest Stable Version](https://camo.githubusercontent.com/1e4b64f510518e5214cd6019c965719418935b8d273e9bcf2c184434e36b8b5f/68747470733a2f2f706f7365722e707567782e6f72672f796969736f66742f796969322d6d6f6e676f64622f762f737461626c652e706e67)](https://packagist.org/packages/yiisoft/yii2-mongodb)[![Total Downloads](https://camo.githubusercontent.com/fbb78cfc2ecd836afc5cb388d357546b77a0d8a0dcbeb6eb3e942e0f6986b934/68747470733a2f2f706f7365722e707567782e6f72672f796969736f66742f796969322d6d6f6e676f64622f646f776e6c6f6164732e706e67)](https://packagist.org/packages/yiisoft/yii2-mongodb)[![Build Status](https://github.com/yiisoft/yii2-mongodb/workflows/build/badge.svg)](https://github.com/yiisoft/yii2-mongodb/actions)[![codecov](https://camo.githubusercontent.com/a8afe756b06727a4b019af18f50afa9f775a2b178f854aaae1f56d7356ad798b/68747470733a2f2f636f6465636f762e696f2f67682f796969736f66742f796969322d6d6f6e676f64622f67726170682f62616467652e7376673f746f6b656e3d31586f38363752364865)](https://codecov.io/gh/yiisoft/yii2-mongodb)

Requirements
------------

[](#requirements)

This extension requires [MongoDB PHP Extension](https://www.php.net/manual/en/set.mongodb.php) version 1.20.1 or higher.

This extension requires MongoDB server version 4.0 or higher.

Installation
------------

[](#installation)

Important

- The minimum required [PHP](https://www.php.net/) version is PHP `7.4`.
- It works best with PHP `8`.

The preferred way to install this extension is through [composer](https://getcomposer.org/download/).

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
-------------

[](#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
------------

[](#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().

###  Health Score

66

—

FairBetter than 99% of packages

Maintenance71

Regular maintenance activity

Popularity62

Solid adoption and visibility

Community50

Growing community involvement

Maturity73

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~161 days

Recently: every ~217 days

Total

27

Last Release

223d ago

Major Versions

2.1.12 → 3.0.02022-09-04

3.0.3 → 22.x-dev2025-05-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/261a6249c6f605f3956a2fae40fbb813f6b2e1e6f2bf806180c851a965426e54?d=identicon)[cebe](/maintainers/cebe)

![](https://www.gravatar.com/avatar/fc29e4e7068a00fe9b9db37b8aadda1db6020adcacef810461e47b99c2b150e6?d=identicon)[samdark](/maintainers/samdark)

![](https://www.gravatar.com/avatar/23416c58e0dce33a8369451a4ca0e28666373594027debc10184b37ade6a926b?d=identicon)[qiangxue](/maintainers/qiangxue)

---

Top Contributors

[![qiangxue](https://avatars.githubusercontent.com/u/993322?v=4)](https://github.com/qiangxue "qiangxue (1913 commits)")[![cebe](https://avatars.githubusercontent.com/u/189796?v=4)](https://github.com/cebe "cebe (761 commits)")[![samdark](https://avatars.githubusercontent.com/u/47294?v=4)](https://github.com/samdark "samdark (693 commits)")[![klimov-paul](https://avatars.githubusercontent.com/u/1482054?v=4)](https://github.com/klimov-paul "klimov-paul (518 commits)")[![creocoder](https://avatars.githubusercontent.com/u/896494?v=4)](https://github.com/creocoder "creocoder (148 commits)")[![resurtm](https://avatars.githubusercontent.com/u/100198?v=4)](https://github.com/resurtm "resurtm (123 commits)")[![tonydspaniard](https://avatars.githubusercontent.com/u/566016?v=4)](https://github.com/tonydspaniard "tonydspaniard (95 commits)")[![Ragazzo](https://avatars.githubusercontent.com/u/1748844?v=4)](https://github.com/Ragazzo "Ragazzo (76 commits)")[![lucianobaraglia](https://avatars.githubusercontent.com/u/374554?v=4)](https://github.com/lucianobaraglia "lucianobaraglia (44 commits)")[![suralc](https://avatars.githubusercontent.com/u/730039?v=4)](https://github.com/suralc "suralc (42 commits)")[![pmoust](https://avatars.githubusercontent.com/u/2493339?v=4)](https://github.com/pmoust "pmoust (36 commits)")[![schmunk42](https://avatars.githubusercontent.com/u/649031?v=4)](https://github.com/schmunk42 "schmunk42 (26 commits)")[![slavcodev](https://avatars.githubusercontent.com/u/757721?v=4)](https://github.com/slavcodev "slavcodev (20 commits)")[![LarryUllman](https://avatars.githubusercontent.com/u/1674823?v=4)](https://github.com/LarryUllman "LarryUllman (18 commits)")[![kartik-v](https://avatars.githubusercontent.com/u/3592619?v=4)](https://github.com/kartik-v "kartik-v (16 commits)")[![mohorev](https://avatars.githubusercontent.com/u/4974062?v=4)](https://github.com/mohorev "mohorev (13 commits)")[![softark](https://avatars.githubusercontent.com/u/342857?v=4)](https://github.com/softark "softark (13 commits)")[![tarasio](https://avatars.githubusercontent.com/u/1010578?v=4)](https://github.com/tarasio "tarasio (12 commits)")[![crtlib](https://avatars.githubusercontent.com/u/4428231?v=4)](https://github.com/crtlib "crtlib (12 commits)")[![bwoester](https://avatars.githubusercontent.com/u/309565?v=4)](https://github.com/bwoester "bwoester (12 commits)")

---

Tags

hacktoberfestmongodbyiiyii2mongodbyii2active-recordmongoGridFS

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yiisoft-yii2-mongodb/health.svg)

```
[![Health](https://phpackages.com/badges/yiisoft-yii2-mongodb/health.svg)](https://phpackages.com/packages/yiisoft-yii2-mongodb)
```

###  Alternatives

[yiisoft/yii2-redis

Redis Cache, Session and ActiveRecord for the Yii framework

48011.7M245](/packages/yiisoft-yii2-redis)[yiisoft/yii2-elasticsearch

Elasticsearch integration and ActiveRecord for the Yii framework

4371.9M15](/packages/yiisoft-yii2-elasticsearch)[yiisoft/yii2-sphinx

Sphinx full text search engine extension for the Yii framework

180997.7k5](/packages/yiisoft-yii2-sphinx)[atk4/data

Agile Data - Database access abstraction framework

2811.7M37](/packages/atk4-data)[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k47](/packages/skeeks-cms)[arogachev/yii2-sortable

Sortable ActiveRecord for Yii 2 framework

1637.0k4](/packages/arogachev-yii2-sortable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
