2015-09-09 29 views
0

我是mongodb中的新成員。我想選擇在MySQL中,我們將賴特的country和特定id如何選擇使用mongoDB和codeigniter的特定字段?

address它作爲

"Select address,country from table_name where user_id=value" 

我怎麼能在MongoDB中使用CodeIgniter實現這個

這裏是我的用戶記錄

array (
    '_id' => '55bb1f3bb117284412000032', 
    'name' => 'Sriram', 
    'email' => '[email protected]', 
    'password' => '123456', 
    'phone' => '354657', 
    'tittle' => 'Ms', 
    'sname' => 'Kumar', 
    'dob' => '07/22/2015', 
    'gender' => 'Male', 
    'address' => 
    array (
    'address' => 'Pantheon road', 
    'street' => 'Egmore', 
    'city' => 'Chennai', 
), 
    'country' => 'India', 

這裏是獲取數據模型文件

$collection = $this->mongo_db->db->selectCollection('Users'); 
$profile = $collection->findOne(array('email' => '[email protected]')); 

我已經試過這樣

$外形= $收藏 - > findOne(陣列( '郵件'=>'[email protected] '))。國家;

,但它不工作

謝謝

回答

2

嘗試以下,讓我知道無論是工作或沒有

$collection->aggregate(
        array(
         '$match' => array(
          '$and' => array(
           array('email' => '[email protected]')   
          ) 
         ) 
        ), 
        array(
         '$group' => array(
          '_id' => '$country' 
         ) 
        ) 
       ); 
+0

是它的工作,但告訴我什麼是部份使用$匹配,$和和$組? – Athi

+1

與MySQL的$匹配比較是哪裏,$和條件不同,在這裏,你可以將多個條件,$組是選擇您想要的字段組 – Tushar

+0

哦確定謝謝 – Athi

相關問題