MongoDB
 sql >> Datenbank >  >> NoSQL >> MongoDB

So schreiben Sie die folgende Mongo-Lookup-Abfrage in Yii2

Lösung gefunden. Es kann jemandem helfen.

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