5

$this->db->query($query)codeigniter で mongoDB executor を作成したいので、このようなクエリ mongoDB をスローする機能はありますか?このクエリを次のように入力すると:

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

... codeigniter はそのクエリを mongodb サーバーに直接スローしますか、それとも別の方法がありますか?

4

1 に答える 1

3

このようなデータベース コマンドを mongodb サーバーに渡すには、 MongoDB PHP Driverを使用する必要があります。MongoDB::command()

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.

アクティブなレコードと一緒に使用したい他のいくつかのライブラリを次に示します。

于 2012-06-02T00:47:21.907 に答える