2017-04-06 5 views
0

아래 코드와 같이 mongodb PHP 응용 프로그램에서 집계 명령을 수행하고 있습니다.mongo db aggregation 결과에서 waitedMS 및 ok를 제거하는 방법은 무엇입니까?

<?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"을 제거 할
[{"waitedMS":0,"result":[{"_id":{"$id":"58d7a6561d78597411000029"},"broadcast_id":35,"studentList":"","employeeList":"999","mailTitle":"hello","broadcastMessage":"how","emailSent":"0","userdetails":[]},{"_id":.... 
... 
"ok":1}] 

으로 표시됩니다 : 0. "result": 및 "ok": json의 1. 출력은 다음과 같아야합니다

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

도와주세요!

+0

출력이 보이지 않지만'$ output [ "result"]'가 아닐까요? – miken32

+0

당신은 절대적으로 맞지만 지금은 [[....]]로 표시하고 싶습니다. [...] – Nida

+0

[PHP로 JSON에서 데이터를 추출하는 방법은 무엇입니까?] (http : // stackoverflow./json-with-php에서 추출한 how-do-i-data-data/29308898) – 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"]; 
관련 문제