PHPackages                             webiny/mongo - 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. [Database &amp; ORM](/categories/database)
4. /
5. webiny/mongo

ActiveLibrary[Database &amp; ORM](/categories/database)

webiny/mongo
============

Webiny Mongo Component

v1.6.1(8y ago)11553MITPHPPHP ^7

Since Sep 19Pushed 8y ago9 watchersCompare

[ Source](https://github.com/Webiny/Mongo)[ Packagist](https://packagist.org/packages/webiny/mongo)[ Docs](http://www.webiny.com/)[ RSS](/packages/webiny-mongo/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (6)Versions (23)Used By (3)

Mongo Component
===============

[](#mongo-component)

Mongo Component is used for working with MongoDB database.

Install the component
---------------------

[](#install-the-component)

The best way to install the component is using Composer.

```
composer require webiny/mongo
```

For additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/mongo).

Configuring Mongo service
-------------------------

[](#configuring-mongo-service)

The recommended way of using Mongo is by defining a Mongo service. Here is an example of defining a service:

```
Mongo:
    Services:
        Webiny:
            Class: \Webiny\Component\Mongo\Mongo
            Arguments:
                Uri: 127.0.0.1:27017
                UriOptions: []
                DriverOptions: []
                CollectionPrefix: 'MyDatabase_'
            Calls:
                - [selectDatabase, [MyDatabase]]
    Driver: \Webiny\Component\Mongo\Bridge\MongoDb
```

Collection prefix will be automatically prepended for you to all database queries.

For more information see: [mongodb/mongo-php-library](http://mongodb.github.io/mongo-php-library/)

After you have defined your Mongo services (in most cases you will only need one, but you can have as many as you like), you can access your Mongo services by using `MongoTrait`:

```
class MyClass {
    use MongoTrait;

    public function test(){
        // MongoTrait uses `Webiny` as a default service name
        $this->mongo()->getCollectionNames();

        // If you have specified your own service name, pass it to mongo method
        $this->mongo('MyMongo')->getCollectionNames();
    }
}
```

### ResultClass

[](#resultclass)

`ResultClass` is used to wrap all Mongo command results. This allows us to have a compatibility layer in case something changes in Mongo response structures in the future and also allows any developer to extend this class and add custom methods to handle mongo response flags.

### Indexes

[](#indexes)

Currently Mongo component supports 3 types of indexes:

- SingleIndex
- CompoundIndex
- TextIndex

To create an index on your collection:

```
// Create a unique single index object
$index = new SingleIndex('Name', 'name', false, true);

// Use mongo trait to create index on your collection
$this->mongo()->createIndex('MyCollection', $index);
```

Resources
---------

[](#resources)

To run unit tests, you need to use the following command:

```
$ cd path/to/Webiny/Component/Mongo/
$ composer.phar install
$ phpunit

```

Make sure you set your MongoDb driver settings in `Tests\ExampleConfig.yaml`.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~52 days

Recently: every ~5 days

Total

22

Last Release

3153d ago

PHP version history (3 changes)v1.0.0PHP &gt;=5.4.0

v1.2.1PHP &gt;=5.5.9

1.5.x-devPHP ^7

### Community

Maintainers

![](https://www.gravatar.com/avatar/4440afa738ed146b05c06073a90345e0464c4f4d042b039532d881ca24859d77?d=identicon)[SvenAlHamad](/maintainers/SvenAlHamad)

---

Top Contributors

[![SvenAlHamad](https://avatars.githubusercontent.com/u/3808420?v=4)](https://github.com/SvenAlHamad "SvenAlHamad (30 commits)")

---

Tags

mongodbmongo

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webiny-mongo/health.svg)

```
[![Health](https://phpackages.com/badges/webiny-mongo/health.svg)](https://phpackages.com/packages/webiny-mongo)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[moloquent/moloquent

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

120114.6k7](/packages/moloquent-moloquent)[leroy-merlin-br/mongolid

Easy, powerful and ultrafast ODM for PHP and MongoDB.

11234.3k4](/packages/leroy-merlin-br-mongolid)[denchikby/phalcon-mongodb-odm

Phalcon MongoDB ODM

4212.8k](/packages/denchikby-phalcon-mongodb-odm)

PHPackages © 2026

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