嗨,我在php驱动程序上有一个mongo $ aggregate的问题 我在PHP中有这个代码:
$match1 = array( '$and' => array(
array("uid" => array('$nin'=> $where_blocked)),
array("type" => "picture" ),
array("active" => true )
));
$match2 = array( '$and' => array(
array("uid" => array('$in'=> $where)),
array("type" => "users" )
));
$query = array(
array(
'$match' => array(
'$or' => array( $match1,$match2 )
),
),
array(
'$lookup' => array(
'from' => 'users',
'localField' => 'objId',
'foreignField' => '_id',
'as' => 'user'
),
),
array(
'$lookup' => array(
'from' => 'pictures',
'localField' => 'objId',
'foreignField' => '_id',
'as' => 'pic'
),
),
array(
'$limit' => $pageSize
),
array(
'$sort' => array("DateCreated" => -1 )
),
array(
'$skip' => $pageSize*($page-1)
)
);
$cursor = $log->aggregate($query);
这是有效的,但我只得到$match1
而不是$match2
我需要得到OR匹配1或匹配2,具体取决于最新的文档。
找到这个工作:
$query_or = array('$or' => array($match1,$match2));
$cursor = $log->find($query_or)->sort(array("DateCreated" => -1))->skip($pageSize*($page-1))->limit($pageSize);
但需要$lookup
(加入),我无法在find
上使用它
有人能帮我吗?
感谢