PHPackages                             crazymeeks/php-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. crazymeeks/php-mongodb

ActiveLibrary

crazymeeks/php-mongodb
======================

Wrapper for php-mongodb library

v1.0.0(4y ago)1883[1 PRs](https://github.com/crazymeeks/php-mongodb/pulls)MITPHPPHP &gt;=7.2

Since Sep 29Pushed 3y ago1 watchersCompare

[ Source](https://github.com/crazymeeks/php-mongodb)[ Packagist](https://packagist.org/packages/crazymeeks/php-mongodb)[ RSS](/packages/crazymeeks-php-mongodb/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

 php-mongodb
 [![](https://camo.githubusercontent.com/23425ffda52a670517e71472043e51b56cd86ce9dfdff65ebcddbfeeee6057a7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6372617a796d65656b732f7068702d6d6f6e676f64622f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://camo.githubusercontent.com/23425ffda52a670517e71472043e51b56cd86ce9dfdff65ebcddbfeeee6057a7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6372617a796d65656b732f7068702d6d6f6e676f64622f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572) [![](https://camo.githubusercontent.com/7431e80bcfc8bc5664d89f52e039a2c4285b1fb9c2ec02a96c15c85a8e983619/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6372617a796d65656b732f7068702d6d6f6e676f64622f6261646765732f6275696c642e706e673f623d6d6173746572)](https://camo.githubusercontent.com/7431e80bcfc8bc5664d89f52e039a2c4285b1fb9c2ec02a96c15c85a8e983619/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6372617a796d65656b732f7068702d6d6f6e676f64622f6261646765732f6275696c642e706e673f623d6d6173746572)
==========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#php-mongodb)

php-mongodb is a PHP library that wraps `MongoDB\Client` library and provides a clean api for interacting with MongoDB database.

### \# System requirements

[](#-system-requirements)

- `>=php7.2`
- `php7.x-mongodb extension`
- `mongodb php driver`

### \# Installation

[](#-installation)

- Install mongodb driver
    - `apt update && apt upgrade -y`
    - `pecl install mongodb-1.9.0`
- Install this library via composer
    - `composer require crazymeeks/php-mongodb`

### \# Usage

[](#-usage)

*Connect to MongoDB Database*

```
use Crazymeeks\MongoDB\Facades\Connection;

Connection::setUpConnection('127.0.0.1', ['username' => 'root', 'password' => 'root'], [])
          ->setDefaultDatabase('testing_mytestdb_crzymix')
          ->connect();
```

*Extend **Crazymeeks\\MongoDB\\Model\\AbstractModel** class*

```
namespace Some\Namespace;

use Crazymeeks\MongoDB\Model\AbstractModel;

class User extends AbstractModel
{

    // Required
    protected $collection = 'users';

    // Required
    protected $fillable = [
        'firstname',
        'lastname',
        'email',
    ];
}
```

### \# Inserting data

[](#-inserting-data)

First approach:

```
$user = new User([
    'firstname' => 'John',
    'lastname' => 'Doe',
    'email' => 'john.doe@example.com',
]);
$user->save();
echo $user->firstname;
// result: John
```

Second approach:

```
$user = User::create([
    'firstname' => 'John',
    'lastname' => 'Doe',
    'email' => 'john.doe@example.com',
]);

echo $user->firstname;
// result: John
```

**Note:** `save()` and `create()` methods will automatically add `created_at` and `updated_at`
timestamps fields when performing an insert. If you wish to disable this, just add `protected $timestamps = true;` to your model class.
Or error, this will throw `\Exception` or `\Error` when something went wrong.

### \# Update

[](#-update)

*Single*

```
$user = new User();
$user->whereEq('firstname', 'John')
     ->update([
         'firstname' => 'Jane',
     ]);
```

*Bulk update*

```
$user = new User();
$user->whereEq('firstname', 'John')
     ->bulkUpdate([
         'firstname' => 'Jane',
     ]);
```

### \# Delete

[](#-delete)

*Single*

```
$user = new User();
$user->whereEq('firstname', 'John')
     ->delete();
```

*Bulk delete*

```
$user = new User();
$user->whereEq('firstname', 'John')
     ->bulkDelete();
```

### \# Finding or Querying data from collection.

[](#-finding-or-querying-data-from-collection)

### Current methods available

[](#current-methods-available)

**whereEq(string $field, string $value)** - where equal query and case-insentive.
**whereNotEq(string $field, string $value)** - where not equal query and case-insensitive.
**whereIn(string $field, array($value1, $value2, ...)** - Case-insensitive.
**whereNotIn(string $field, array($value1, array $value2, ...)** - Case-insensitive.
**whereGreater(string $field, mixed $value)** $value could be int|string. Works great for int types.
**whereGreaterOrEq(string $field, mixed $value)** - $value could be int|string. Works great for int types.
**whereLessThanOrEq(string $field, mixed $value)** - $value could be int|string. Works great for int types.
**whereLessThan(string $field, mixed $value)** - $value could be int|string. Works great for int types.
**first()** - Returns object that extends \\Crazymeeks\\MongoDB\\Model\\AbstractModel. You may `count()` result of this function for counter checking.
**get()** - Returns an array object that extends \\Crazymeeks\\MongoDB\\Model\\AbstractModel. You may `count()` result of this function for counter checking.

### \# Query samples

[](#-query-samples)

```
$user = new User();
$result = $user->whereEq('firstname', 'John')->first();
if (count($result) > 0) {
    echo $result->firstname;
    // result: John
}
```

### \# Chaining multiple queries

[](#-chaining-multiple-queries)

You may chain multiple queries too.

```
$user = new User();
$users = $user->whereEq('email', 'john.doe@example.com')
                ->whereIn('name', ['john'])
                ->get();
foreach($users as $user){
    echo $user->name . "";
}
// or you may also call methods statically
$users = User::whereEq('email', 'john.doe@example.com')
                ->whereIn('name', ['john'])
                ->get();
```

\#Direct Usage
--------------

[](#direct-usage)

**In addition, you may also use all methods available in [MongoDB\\Client](https://docs.mongodb.com/php-library/current/tutorial/) and call it directly in your model.**

```
$user = new User();
$find = $user->findOne(['name' => 'John']);
```

### \# Laravel integration

[](#-laravel-integration)

Register connection to app service provider.

```
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Crazymeeks\MongoDB\Facades\Connection;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

        Connection::setUpConnection('127.0.0.1', ['username' => 'root', 'password' => 'root'], [])
          ->setDefaultDatabase('testing_mytestdb_crzymix')
          ->connect();
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
```

*Model*

```
namespace App;

use Crazymeeks\MongoDB\Model\AbstractModel;

class User extends AbstractModel
{
    protected $collection = 'users';

    protected $fillable = [
        'firstname',
        'lastname',
        'email',
    ];

}
```

**Important:** Laravel's relationship is not yet supported.

Author: Jeff Claud

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

1693d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/07c8c7c06de29afbc4fbc9e66f5fcc320c499057969ce341730590355d6d6145?d=identicon)[jepoy](/maintainers/jepoy)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/crazymeeks-php-mongodb/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

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

PHP Doctrine MongoDB Object Document Mapper (ODM) provides transparent persistence for PHP objects to MongoDB.

1.1k23.3M302](/packages/doctrine-mongodb-odm)[alcaeus/mongo-php-adapter

Adapter to provide ext-mongo interface on top of mongo-php-library

46412.3M73](/packages/alcaeus-mongo-php-adapter)[facile-it/mongodb-bundle

Bundle service integration of official \[mongodb/mongo-php-library\](https://github.com/mongodb/mongo-php-library) driver library

38212.1k1](/packages/facile-it-mongodb-bundle)[league/flysystem-gridfs

20498.3k21](/packages/league-flysystem-gridfs)[emag-tech-labs/messenger-mongo-bundle

A Mongo transport for the Symfony Messenger component

16196.8k](/packages/emag-tech-labs-messenger-mongo-bundle)

PHPackages © 2026

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