Interaction with MongoDB in CodeIgniter

Is there a function to throw a mongoDB request like this $this->db->query($query)because I want to create a mongoDB executor in codeigniter, so if I type this request like this:

db.users.find({age:33}) 

... codeigniter to throw this request directly to the mongodb server or is there another way?

+5
source share
1 answer

You should use the MongoDB PHP Driver MongoDB::command() to transfer such database commands to the mongodb server.

CodeIgniter MongoDB, , . , CodeIgniter MongoDB Active Record. :

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

, :

+3

All Articles