2017-04-06 33 views
0

我正在mongodb php應用程序中執行聚合命令,如下面的代碼行。如何從mongo數據庫聚合結果中刪除waitedMS並確定?

<?php 

$query = array('$or' => array(
    array('employeeList'=>array('$exists' => false)), 
    array('employeeList'=>array('$eq' => null)), 
    array('employeeList'=>array('$eq' => ",")), 
    array('employeeList'=>array('$eq' => "")) 
)); 

$pipeline = array(
    array(
     '$match' => $query 
    ), 
    array(
     '$lookup' => array(
      'from' => 'userTbl', 
      'localField' => 'user_id', 
      'foreignField' => 'uid', 
      'as' => 'userdetails' 
     ) 
    ), 
); 

$output = $this->db->broadcastTbl->aggregate($pipeline); 
$result =array(); 
array_push($result, $output); 

現在的輸出顯示爲

[{"waitedMS":0,"result":[{"_id":{"$id":"58d7a6561d78597411000029"},"broadcast_id":35,"studentList":"","employeeList":"999","mailTitle":"hello","broadcastMessage":"how","emailSent":"0","userdetails":[]},{"_id":.... 
... 
"ok":1}] 

我想刪除 「waitedMS」:0。 「結果」:和「ok」:1來自json。輸出應該像

[{"_id":{"$id":"58d7a6561d78597411000029"},"broadcast_id":35,"studentList":"","employeeList":"999","mailTitle":"hello","broadcastMessage":"how","emailSent":"0","userdetails":[]}, ... 
] 

請幫助我!

+0

我沒有在這裏看到任何輸出,但不會是'$ output [「result」]'然後呢? – miken32

+0

你是絕對正確的,但現在正在顯示爲[[...]],我想[0123] []] – Nida

+0

[我如何從PHP提取JSON數據?](http:// stackoverflow。 COM /問題/ 29308898 /如何-DO-I-提取數據從 - JSON-與-PHP) – miken32

回答

1

您只需訪問「結果」項即可。不要將它推到另一個陣列上。

<?php 

$query = array('$or' => array(
    array('employeeList'=>array('$exists' => false)), 
    array('employeeList'=>array('$eq' => null)), 
    array('employeeList'=>array('$eq' => ",")), 
    array('employeeList'=>array('$eq' => "")) 
)); 

$pipeline = array(
    array(
     '$match' => $query 
    ), 
    array(
     '$lookup' => array(
      'from' => 'userTbl', 
      'localField' => 'user_id', 
      'foreignField' => 'uid', 
      'as' => 'userdetails' 
     ) 
    ), 
); 

$output = $this->db->broadcastTbl->aggregate($pipeline); 

$result = $output["result"];