我有此查询,它为两个日期字段不相等的每个事件数组元素返回_id。在mongo客户端中可以正常工作:
db.endUsers.aggregate([{$match:{'events':{$elemMatch:{'lastinvitedate":{$exists:true},"originalinvitedate":{$exists:true},}}}},{$unwind: "$events"},{$match: {'events.lastinvitedate":{$exists:true},"events.originalinvitedate":{$exists:true},}},{$project: { eventid: { $cond: { if : { $ne: ['$events.lastinvitedate', $events.originalinvitedate' ] }, then:'$events._id', else: 0}}}},{$redact: {$cond: {if: { $eq: [ "$eventid", 0 ] },then: '$$PRUNE',else: '$$DESCEND'}}}])
当我用php编写时没有任何结果
$pipeline = [
['$match' => [
'events' => [
'$elemMatch' => [
'lastinvitedate' => ['$exists' => true],
'originalinvitedate' => ['$exists' => true],
],
]
]
],
['$unwind' => '$events'],
['$match' => [
'events.lastinvitedate' => ['$exists' => true],
'events.originalinvitedate' => ['$exists' => true],
]
],
['$project' => [
'eventId' => [ '$cond' =>
[ 'if' =>
[ '$ne' =>
['$events.originalinvitedate', '$events.lastinvitedate' ]
],
'then' => '$events._id',
'else' => 0
]
],
]
],
[ '$redact' => [ '$cond' =>
[ 'if' =>
[ '$eq' =>
[ '$eventid', 0 ]
],
'then' => '$$PRUNE',
'else' => '$$DESCEND'
]
]
]
];
任何线索为何? 谢谢