Interfacing with MongoDB in CodeIgniter Interfacing with MongoDB in CodeIgniter mongodb mongodb

Interfacing with MongoDB in CodeIgniter


You should use MongoDB PHP Driver's MongoDB::command() for passing such database commands to the mongodb server.

In CodeIgniter there are a few community-built MongoDB libraries you can use. Since I checked almost all of them, take my advise and use CodeIgniter MongoDB Active Record. Here's a sample code:

<?php// Somewhere in your model, controller, etc.// Load MongoDB library$this->load->library('mongo_db');// Query MongoDB: Active document library usage example$docs = $this->mongo_db->where('age', '33')->get('collection_name_here');  // Query MongoDB: Command usage example$docs = $this->mongo_db->command(array(    'geoNear'    => 'buildings',     'near'       => array(53.228482, -0.547847),     'num'        => 10,     'nearSphere' => TRUE,));// Theme results, pass to the view, etc.

Here are a few other libraries around that you might want to use alongside the active record one: