[COMPASS-3714] Compass Generate Error on pipeline stage but shell run fine Created: 23/Jun/19  Updated: 29/Oct/23  Resolved: 17/Mar/20

Status: Closed
Project: Compass
Component/s: Aggregation pipeline, Compass, Grammar
Affects Version/s: None
Fix Version/s: 1.22.0

Type: Bug Priority: Major - P3
Reporter: Hassan Faghihi Assignee: Durran Jordan
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows Server 2016,
MongoD 4.0.4


Issue Links:
Duplicate
is duplicated by COMPASS-3713 While others run Aggregation Query, C... Closed
Problem/Incident
causes COMPASS-4146 Disable validation in agg builder, qu... Closed
Sprint: Iteration Ragamuffin

 Description   

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" : ----------
}

 
 
 


Generated at Wed Feb 07 22:34:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.