Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-3714

Compass Generate Error on pipeline stage but shell run fine

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.22.0
    • Affects Version/s: None
    • None
    • Environment:
      Windows Server 2016,
      MongoD 4.0.4
    • Iteration Ragamuffin

      When i try to run aggregation query, in one of my stage i receive following error; while the query itself is runnable elsewheres:

      Expected "[" or AggregationStage but "{" found.

      The stage is as following:

      // stage: $addFields
      
      /**
       * newField - The new field name.
       * expression - The new field expression.
       */
      {
        "User.ProfilePictures": {
          $cond:[
            {
              $and:[
                {$ne:["User.ProfilePictures",undefined]},
                {$ne:["User.ProfilePictures",null]}
              ]
            },
            {
              $cond:[
                { 
                  $ne: [
                    {
                      $indexOfArray: [
                        "$User.ProfilePictures.IsMain",
                        true
                      ]
                    }, 
                    -1
                  ]
                },
                {
                  $arrayElemAt: [
                    "$User.ProfilePictures", 
                    {
                      $indexOfArray: 
                      [
                        "$User.ProfilePictures.IsMain",
                        true
                      ]
                    }
                  ]
                },
                {
                  $arrayElemAt: [
                    "$User.ProfilePictures",
                    0
                  ]
                }
              ]
            },
            null
          ]
        }
      }
      

       
      and the whole stages are like this:

      // Requires official MongoShell 3.6+
      use realEstate;
      db.getCollection("basePlace").aggregate(
          [
              { 
                  "$lookup" : {
                      "from" : "humanResource.user", 
                      "localField" : "UserId", 
                      "foreignField" : "_id", 
                      "as" : "User"
                  }
              }, 
              { 
                  "$unwind" : {
                      "path" : "$User", 
                      "preserveNullAndEmptyArrays" : true
                  }
              }, 
              { 
                  "$addFields" : {
                      "User.ProfilePictures" : {
                          "$map" : {
                              "input" : "$User.ProfilePictures", 
                              "as" : "pp", 
                              "in" : {
                                  "ImageId" : "$$pp.ImageId", 
                                  "CloudinaryUrl" : "$$pp.CloudinarySecureUrl", 
                                  "IsMain" : "$$pp.IsMain", 
                                  "Title" : "$$pp.Title", 
                                  "Description" : "$pp.Description"
                              }
                          }
                      }
                  }
              }, 
              { 
                  "$addFields" : {
                      "User.ProfilePictures" : {
                          "$cond" : [
                              {
                                  "$and" : [
                                      {
                                          "$ne" : [
                                              "User.ProfilePictures", 
                                              undefined
                                          ]
                                      }, 
                                      {
                                          "$ne" : [
                                              "User.ProfilePictures", 
                                              null
                                          ]
                                      }
                                  ]
                              }, 
                              {
                                  "$cond" : [
                                      {
                                          "$ne" : [
                                              {
                                                  "$indexOfArray" : [
                                                      "$User.ProfilePictures.IsMain", 
                                                      true
                                                  ]
                                              }, 
                                              -1.0
                                          ]
                                      }, 
                                      {
                                          "$arrayElemAt" : [
                                              "$User.ProfilePictures", 
                                              {
                                                  "$indexOfArray" : [
                                                      "$User.ProfilePictures.IsMain", 
                                                      true
                                                  ]
                                              }
                                          ]
                                      }, 
                                      {
                                          "$arrayElemAt" : [
                                              "$User.ProfilePictures", 
                                              0.0
                                          ]
                                      }
                                  ]
                              }, 
                              null
                          ]
                      }
                  }
              }, 
              { 
                  "$match" : {
                      "User.ProfilePictures" : {
                          "$ne" : null
                      }
                  }
              }
          ], 
          { 
              "allowDiskUse" : false
          }
      );
      
      

      My Schema....
      My BasePlace has a reference of a Uset:

      { 
          "_id" : ObjectId("5d06374370de7d26089024e0"), 
          "_t" : "BasePlace", 
          "UserId" : ObjectId("5d06285570de7d11606275f4"), 
           ...

      And here's my implementation of Microsoft Identity:
       

      { 
          "_id" : ObjectId("5d066f0a5e82a42f105a8811"), 
          "UserName" : ------------------, 
          "UserNameLowerCase" : ----------------, 
          "CreateDateTime" : ISODate("2019-06-16T16:32:10.739+0000"), 
          "UpdateDateTime" : ISODate("2019-06-16T16:36:38.563+0000"), 
          "PasswordHash" : ----------------------------, 
          "SecurityStamp" : null, 
          "TwoFactorEnabled" : false, 
          "PhoneNumber" : null, 
          "PhoneNumberStandard" : null, 
          "IsPhoneNumberConfirmed" : false, 
          "Email" : -------------------------, 
          "EmailLowerCase" : ------------------------, 
          "IsEmailConfirmed" : false, 
          "IsLockoutEnabled" : false, 
          "LockoutEndDateUtc" : [
              NumberLong(0), 
              NumberInt(0)
          ], 
          "AccessFailedCount" : NumberInt(0), 
          "Roles" : [
              {
                  "RoleId" : ObjectId("5c3c263970de7d2e88a93623"), 
                  "Name" : "User", 
                  "NameLowerCase" : "user"
              }
          ], 
          "Owner" : {
              "_t" : [
                  "Owner", 
                  "Person"
              ], 
              "Nickname" : null, 
              "Introduction" : null, 
              "FirstName" : null, 
              "LastName" : null, 
              "OwnerTitle" : NumberInt(0), 
              "ContactEmail" : null, 
              "ContactTel1" : null, 
              "ContactTel2" : null
          }, 
          "ProfilePictures" : [
              {
                  "ImageId" : ObjectId("5d0670165e82a42f105a8812"), 
                  "CloudinaryPublicId" : ----------------, 
                  "CloudinaryUrl" : --------------, 
                  "IsMain" : true, 
                  "Title" : "vira.1368 Profile Picture", 
                  "Description" : null, 
                  "CloudinarySecureUrl" : --------------
              }
          ], 
          "RegisteringIpAddress" : ----------
      }
      

       
       
       

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            deadmann Hassan Faghihi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: