Equality Match not working in $expr

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Hi

      yii::$app->mongodb->GetCollection('sessions')->Aggregate([
          [
              '$lookup' => [
                  'from' => 'users',
                  'localField' => '_userId',
                  'foreignField' => '_id',
                  'let' => ['sRoleId' => '$_roleId'],
                  'pipeline' => [
                      [
                          '$match' => [
                              'enable' => true,
                          ],
                      ],
                      [
                          '$lookup' => [
                              'from' => 'roles',
                              'pipeline' => [
                                  [
                                      '$match' => [
                                          //'$expr' => ['$_id' => '$$sRoleId'],          //Error
                                          //'$expr' => ['x' => 'y'],                    //Always is true and return all docs
                                          '$expr' => ['$eq' => ['$_id','$$sRoleId']],  //OK
                                      ],
                                  ],
                              ],
                              'as' => 'role',
                          ],
                      ],
                  ],
                  'as' => 'user',
              ],
          ],
      ]);
      

            Assignee:
            Unassigned
            Reporter:
            Abolfazl Ziaratban
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: