sql >> Base de Datos >  >> NoSQL >> MongoDB

Cómo escribir la siguiente consulta de búsqueda de mongo en Yii2

Encontré la solución. Puede ayudar a alguien.

$collection = Yii::$app->mongodb->getCollection('ServiceProvider');
$result = $collection->aggregate([
            ['$unwind' => '$PostCommentUserIDs'],
            [ 
                '$lookup' => 
                    [
                        'from' => 'Parents',
                        'localField' => 'PostCommentUserIDs',
                        'foreignField' => 'ID',
                        'as' => 'ParentDetails'
                    ] 
            ],
            [
                '$match' => [
                    'ParentDetails' => [ '$ne' => []  ]
                ]
            ]
]);