Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-58867

Equality Match not working in $expr

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

      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 Unassigned
            Reporter:
            abolfazl.ziaratban@gmail.com Abolfazl Ziaratban
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: