Intekhab Rizvi

MongoDB library for CodeIgniter 3

Run MongoDB queries from CodeIgniter 3 in the same chained, active-record style you already use for SQL.

Language
PHP 7+
Framework
CodeIgniter 3
Requires
mongodb 1.5.x extension
Licence
MIT

Overview

CIMongo lets you query MongoDB from CodeIgniter with chained methods such as where(), order_by() and limit(). It supports write concern and journal options, read preference, the aggregation framework and query profiling.

Compatibility

  • PHP 7 or higher and CodeIgniter 3.
  • The PECL mongodb 1.5.x extension.
  • Copied into your application, not published on Packagist, so there is no composer require.
  • A branch named unitesting holds the code used for unit tests.

Installation

  1. Download the repository. It contains config and libraries folders.
  2. Copy both into your CodeIgniter application folder.
  3. Set your connection details in application/config/mongo_db.php.
  4. Autoload the library in application/config/autoload.php:
    $autoload['libraries'] = array('mongo_db');
    

Usage

$users = $this->mongo_db
    ->where(array('age' => 31))
    ->order_by(array('name' => 'asc'))
    ->limit(10)
    ->get('users');

The full method list, including multiple connections, is in the original CIMongo documentation. To see the queries your app runs, add CIProfiler.