Sorting very slow after lookup in aggregation, could you suggest any method

Sorting very slow after lookup in aggregation, Search also taking time to find. Lighting fast before lookup but after lookup very slow for just 3000 records response.

Hi @Pradeep_Susairaj - Welcome to the community.

Sorting very slow after lookup in aggregation, Search also taking time to find. Lighting fast before lookup but after lookup very slow for just 3000 records response.

Sorry but I do not believe there is enough information provided to be able to assist further here. Could you provide the following details so that we have a better idea of what the issue could possibly be:

Regards,
Jason

2 Likes

Image:

Aggregation Pipeline:


[{$sort: {
 'Data.name': 1
}}, {$match: {
 ParentId: null
}}, {$addFields: {
 _graphlookupId: {
  $toString: '$_id'
 }
}}, {$lookup: {
 from: 'Account',
 'let': {
  localId: {
   $toString: '$_id'
  }
 },
 pipeline: [
  {
   $match: {
    $expr: {
     $and: [
      {
       $eq: [
        {
         $type: '$Ancestors'
        },
        'array'
       ]
      },
      {
       $in: [
        '$$localId',
        '$Ancestors'
       ]
      }
     ]
    }
   }
  }
 ],
 as: 'Children'
}}, {$set: {
 'Data.type': {
  $function: {
   body: 'function(value, isMultiSelect) {if (!value) {return isMultiSelect ? {_t:\'System.String[]\', _v: [] } : null} else if (typeof value === \'string\'){return isMultiSelect ? {_t:\'System.String[]\', _v: [ value ] } : value} else if (typeof value === \'object\' && value._v != null && Array.isArray(value._v)) {return isMultiSelect ? value : ( value._v.length ? value._v[0] : {_t:\'System.String[]\', _v: [] } );} else {return isMultiSelect ? {_t:\'System.String[]\', _v: [] } : null}}',
   args: [
    '$Data.type',
    false
   ],
   lang: 'js'
  }
 }
}}, {$set: {
 'Data.type': {
  $filter: {
   input: [
    {
     name: 'account',
     value: 'account',
     color: ''
    },
    {
     name: 'lead',
     value: 'lead',
     color: ''
    },
    {
     name: 'supplier',
     value: 'supplier',
     color: ''
    },
    {
     name: 'customer',
     value: 'customer',
     color: ''
    }
   ],
   as: 'item',
   cond: {
    $eq: [
     '$$item.value',
     '$Data.type'
    ]
   }
  }
 }
}}, {$set: {
 'Data.assigned_to': {
  $function: {
   body: 'function(value, isMultiSelect) {if (!value) {return isMultiSelect ? {_t:\'System.String[]\', _v: [] } : null} else if (typeof value === \'string\'){return isMultiSelect ? {_t:\'System.String[]\', _v: [ value ] } : value} else if (typeof value === \'object\' && value._v != null && Array.isArray(value._v)) {return isMultiSelect ? value : ( value._v.length ? value._v[0] : {_t:\'System.String[]\', _v: [] } );} else {return isMultiSelect ? {_t:\'System.String[]\', _v: [] } : null}}',
   args: [
    '$Data.assigned_to',
    false
   ],
   lang: 'js'
  }
 }
}}, {$lookup: {
 from: 'User',
 'let': {
  assigned_to: '$Data.assigned_to'
 },
 pipeline: [
  {
   $match: {
    $expr: {
     $eq: [
      '$_id',
      {
       $toObjectId: '$$assigned_to'
      }
     ]
    }
   }
  },
  {
   $project: {
    name: {
     $concat: [
      '$FirstName',
      ' ',
      '$LastName'
     ]
    }
   }
  }
 ],
 as: 'Data.assigned_to'
}}, {$lookup: {
 from: 'User',
 'let': {
  localId: {
   $toObjectId: '$Created_By'
  }
 },
 pipeline: [
  {
   $match: {
    $expr: {
     $eq: [
      '$$localId',
      '$_id'
     ]
    }
   }
  },
  {
   $project: {
    name: {
     $concat: [
      '$FirstName',
      ' ',
      '$LastName'
     ]
    }
   }
  }
 ],
 as: 'Created_By'
}}, {$lookup: {
 from: 'User',
 'let': {
  localId: {
   $toObjectId: '$Modified_By'
  }
 },
 pipeline: [
  {
   $match: {
    $expr: {
     $eq: [
      '$$localId',
      '$_id'
     ]
    }
   }
  },
  {
   $project: {
    name: {
     $concat: [
      '$FirstName',
      ' ',
      '$LastName'
     ]
    }
   }
  }
 ],
 as: 'Modified_By'
}}, {$project: {
 'Data.selectdefault': 0,
 'Data.user': 0,
 'Data.r_contact': 0,
 'Data.textareatest': 0,
 'Data.checkboxtest': 0,
 'Data.radiotest': 0,
 'Data.selectmoduletest': 0,
 'Data.selectmulticustomtest': 0,
 'Data.selectmultimoduletest': 0,
 'Data.selectmultidefaulttest': 0,
 'Data.emailtest': 0,
 'Data.numbertest': 0,
 'Data.phonetest': 0,
 'Data.usertest': 0,
 'Data.gender': 0,
 'Data.moduletest': 0,
 'Data.defaulttest': 0,
 'Data.shipping_post': 0,
 'Data.shipping_country': 0,
 'Data.shipping_state': 0,
 'Data.shipping_city': 0,
 'Data.shipping_street3': 0,
 'Data.shipping_street2': 0,
 'Data.shipping_street': 0,
 'Data.shipping_address_divider': 0,
 'Data.billing_post': 0,
 'Data.billing_country': 0,
 'Data.billing_state': 0,
 'Data.billing_city': 0,
 'Data.billing_street3': 0,
 'Data.billing_street2': 0,
 'Data.billing_street': 0,
 'Data.billing_address_divider': 0,
 'Data.cansendnotification': 0,
 'Data.ticketdomain': 0,
 'Data.rating': 0,
 'Data.sic_code': 0,
 'Data.ownership': 0,
 'Data.web': 0,
 'Data.alternate_phone': 0,
 'Data.alternative_email': 0,
 'Data.industry': 0
}}, {$facet: {
 count: [
  {
   $count: 'count'
  }
 ],
 data: [
  {
   $limit: 25
  },
  {
   $skip: 0
  }
 ]
}}, {$match: {
 _id: {
  $ne: null
 }
}}, {$group: {
 _id: 'Count',
 count: {
  $sum: 1
 }


Sample Document(Account):
{  "_id": {    "$oid": "62020b72400d7a5618cc73c4"  },  "Modified_At": {    "$date": "2022-04-01T08:29:16.383Z"  },  "Created_At": {    "$date": "2022-02-08T06:19:30.594Z"  },  "Deleted": false,  "Data": {    "name": "Ajay",    "assigned_to": "6232dea34022ba2d4c99ffa7",    "type": "account",    "industry": "",    "annual_revenue": "fgh",    "email": "aa@gmail.com",    "alternative_email": "",    "office_phone": "",    "alternate_phone": "",    "web": "",    "ownership": "",    "sic_code": "",    "rating": "0.0",    "ticketdomain": "",    "cansendnotification": false,    "description": "",    "billing_street": "",    "billing_street2": "",    "billing_street3": "",    "billing_city": "",    "billing_state": "",    "billing_country": "",    "billing_post": "",    "shipping_street": "",    "shipping_street2": "",    "shipping_street3": "",    "shipping_city": "",    "shipping_state": "",    "shipping_country": "",    "shipping_post": "",    "defaulttest": {      "_t": "System.String[]",      "_v": [        "DefaultTest"      ]    },    "moduletest": "62020bb1400d7a5618cc73c7",    "gender": "",    "usertest": {      "_t": "System.String[]",      "_v": [        "61d6894c1b28032fdcee43b7"      ]    },    "phonetest": "",    "numbertest": "0.0",    "emailtest": "",    "selectmultidefaulttest": {      "_t": "System.String[]",      "_v": [        "1",        "2"      ]    },    "selectmultimoduletest": {      "_t": "System.String[]",      "_v": [        "62020b72400d7a5618cc73c4",        "62020bb1400d7a5618cc73c7"      ]    },    "selectmoduletest": {      "_t": "System.String[]",      "_v": [        "62020b72400d7a5618cc73c4",        "620289621d0c42eec4b8da47"      ]    },    "radiotest": "1",    "checkboxtest": false,    "textareatest": "",    "r_contact": "b",    "user": "61d6894c1b28032fdcee43b7",    "selectdefault": "pradeep"  },  "SharePoint_Id": "01DNMZ6ILZUZJ5AWXCUFG3SZOCUCDRSABJ",  "Tripletex_Id": 0,  "Uni_Id": 0,  "MailChimpId": null,  "Relations": [    {      "Module": "Account",      "_id": "620289561d0c42eec4b8da43",      "IsMain": false    },    {      "Module": "Account",      "_id": "62020bb1400d7a5618cc73c7",      "IsMain": false    },    {      "Module": "Contact",      "_id": "6225a0f645ac720ea0c99685",      "IsMain": true    }  ],  "Permissions": [    {      "Group_Id": "61d689491b28032fdcee4344",      "User_Id": null,      "Access_Level": "manage"    },    {      "Group_Id": "61d689491b28032fdcee4345",      "User_Id": null,      "Access_Level": "view"    }  ],  "Created_By": "61d6894c1b28032fdcee43b7",  "Modified_By": "61d6894c1b28032fdcee43b7",  "ProfileImage": "",  "OutlookOrganizerId": null,  "ParentId": null,  "Ancestors": null}

Sample Document(User):
{  "_id": {    "$oid": "61d6894c1b28032fdcee43b7"  },  "Modified_At": {    "$date": "2022-01-06T06:16:43Z"  },  "Created_At": {    "$date": {      "$numberLong": "-62135596800000"    }  },  "Deleted": false,  "FirstName": "Pradeep",  "LastName": "S",  "IsSharePointUser": true,  "Password": null,  "Email": "pradeep@****.com",  "Phone": null,  "Role": 0,  "DepartmentId": 0,  "Pin": null,  "Signature": null,  "SendMailNotification": null,  "IsActive": true,  "IsAdmin": true,  "IsContentAdmin": true,  "Groups": [    "61d689491b28032fdcee4345"  ],  "NormalWorkingHours": 8,  "TotalWorkingHoursPerWeek": 50,  "WeekToStartTimeBankCalculation": 1,  "YearToStartTimeBankCalculation": 2022,  "TotalAbsenceHoursPerYear": 100,  "AvailableAbsenceHours": 0,  "ResourcePlannerStatus": null,  "LandingPageAfterLogin": "/module/Event/61d689491b28032fdcee4349",  "Profile": "avatars/3fcfde85-057a-40b1-8181-a2dd9b33a326.webp",  "LastLogin": {    "$date": "2022-04-18T04:52:43.703Z"  }}

}}]

Execution Stats:
{ explainVersion: ‘1’,
stages:
[ { ‘$cursor’:
{ queryPlanner:
{ namespace: ‘crm_processdrivecom_Timeline.Account’,
indexFilterSet: false,
parsedQuery: { ParentId: { ‘$eq’: null } },
maxIndexedOrSolutionsReached: false,
maxIndexedAndSolutionsReached: false,
maxScansToExplodeReached: false,
winningPlan: { stage: ‘EOF’ },
rejectedPlans: [] },
executionStats:
{ executionSuccess: true,
nReturned: 0,
executionTimeMillis: 1,
totalKeysExamined: 0,
totalDocsExamined: 0,
executionStages:
{ stage: ‘EOF’,
nReturned: 0,
executionTimeMillisEstimate: 0,
works: 1,
advanced: 0,
needTime: 0,
needYield: 0,
saveState: 1,
restoreState: 1,
isEOF: 1 },
allPlansExecution: [] } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$addFields’: { _graphlookupId: { ‘$convert’: { input: ‘$_id’, to: { ‘$const’: ‘string’ } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘Test’,
as: ‘Children’,
let: { localId: { ‘$convert’: { input: ‘$_id’, to: { ‘$const’: ‘string’ } } } },
pipeline:
[ { ‘$match’:
{ ‘$expr’:
{ ‘$and’:
[ { ‘$eq’: [ { ‘$type’: ‘$Ancestors’ }, ‘array’ ] },
{ ‘$in’: [ ‘$$localId’, ‘$Ancestors’ ] } ] } } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Data:
{ usermultiselect:
{ ‘$function’:
{ body: ‘function(value, isMultiSelect) {if (!value) {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null} else if (typeof value === ‘string’){return isMultiSelect ? {_t:‘System.String[]’, _v: [ value ] } : value} else if (typeof value === ‘object’ && value._v != null && Array.isArray(value._v)) {return isMultiSelect ? value : ( value._v.length ? value._v[0] : {_t:‘System.String[]’, _v: [] } );} else {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null}}’,
args: [ ‘$Data.usermultiselect’, { ‘$const’: true } ],
lang: ‘js’ } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$unwind’:
{ path: ‘$Data.usermultiselect._v’,
preserveNullAndEmptyArrays: true },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$addFields’:
{ convertObjectId:
{ ‘$convert’:
{ input: ‘$Data.usermultiselect._v’,
to: { ‘$const’: ‘objectId’ } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘User’,
as: ‘Data.usermultiselect’,
let: { id: ‘$convertObjectId’ },
pipeline:
[ { ‘$match’: { ‘$expr’: { ‘$eq’: [ ‘$$id’, ‘$_id’ ] } } },
{ ‘$project’: { name: { ‘$concat’: [ ‘$FirstName’, ’ ', ‘$LastName’ ] } } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$project’: { convertObjectId: false, _id: true },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$unwind’:
{ path: ‘$Data.usermultiselect’,
preserveNullAndEmptyArrays: true },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$group’:
{ _id: ‘$_id’,
Data_usermultiselect: { ‘$push’: ‘$Data.usermultiselect’ },
temp: { ‘$first’: ‘$$ROOT’ } },
maxAccumulatorMemoryUsageBytes: { Data_usermultiselect: 0, temp: 0 },
totalOutputDataSizeBytes: 0,
usedDisk: false,
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’: { temp: { Data: { usermultiselect: ‘$Data_usermultiselect’ } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$replaceRoot’: { newRoot: ‘$temp’ },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Data:
{ userselect:
{ ‘$function’:
{ body: ‘function(value, isMultiSelect) {if (!value) {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null} else if (typeof value === ‘string’){return isMultiSelect ? {_t:‘System.String[]’, _v: [ value ] } : value} else if (typeof value === ‘object’ && value._v != null && Array.isArray(value._v)) {return isMultiSelect ? value : ( value._v.length ? value._v[0] : {_t:‘System.String[]’, _v: [] } );} else {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null}}’,
args: [ ‘$Data.userselect’, { ‘$const’: false } ],
lang: ‘js’ } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘User’,
as: ‘Data.userselect’,
let: { assigned_to: ‘$Data.userselect’ },
pipeline:
[ { ‘$match’: { ‘$expr’: { ‘$eq’: [ ‘$_id’, { ‘$toObjectId’: ‘$$assigned_to’ } ] } } },
{ ‘$project’: { name: { ‘$concat’: [ ‘$FirstName’, ’ ', ‘$LastName’ ] } } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Data:
{ selectmultimodule:
{ ‘$function’:
{ body: ‘function(value, isMultiSelect) {if (!value) {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null} else if (typeof value === ‘string’){return isMultiSelect ? {_t:‘System.String[]’, _v: [ value ] } : value} else if (typeof value === ‘object’ && value._v != null && Array.isArray(value._v)) {return isMultiSelect ? value : ( value._v.length ? value._v[0] : {_t:‘System.String[]’, _v: [] } );} else {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null}}’,
args: [ ‘$Data.selectmultimodule’, { ‘$const’: true } ],
lang: ‘js’ } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$unwind’:
{ path: ‘$Data.selectmultimodule._v’,
preserveNullAndEmptyArrays: true },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$addFields’:
{ convertObjectId:
{ ‘$convert’:
{ input: ‘$Data.selectmultimodule._v’,
to: { ‘$const’: ‘objectId’ } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘Contact’,
as: ‘Data.selectmultimodule’,
let: { id: ‘$convertObjectId’ },
pipeline:
[ { ‘$match’: { ‘$expr’: { ‘$eq’: [ ‘$$id’, ‘$_id’ ] } } },
{ ‘$project’: { Name: ‘$Data.name’ } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$project’: { convertObjectId: false, _id: true },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$unwind’:
{ path: ‘$Data.selectmultimodule’,
preserveNullAndEmptyArrays: true },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$group’:
{ _id: ‘$_id’,
Data_selectmultimodule: { ‘$push’: ‘$Data.selectmultimodule’ },
temp: { ‘$first’: ‘$$ROOT’ } },
maxAccumulatorMemoryUsageBytes: { Data_selectmultimodule: 0, temp: 0 },
totalOutputDataSizeBytes: 0,
usedDisk: false,
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’: { temp: { Data: { selectmultimodule: ‘$Data_selectmultimodule’ } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$replaceRoot’: { newRoot: ‘$temp’ },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Data:
{ selectmultidefault:
{ ‘$function’:
{ body: ‘function(value, isMultiSelect) {if (!value) {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null} else if (typeof value === ‘string’){return isMultiSelect ? {_t:‘System.String[]’, _v: [ value ] } : value} else if (typeof value === ‘object’ && value._v != null && Array.isArray(value._v)) {return isMultiSelect ? value : ( value._v.length ? value._v[0] : {_t:‘System.String[]’, _v: [] } );} else {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null}}’,
args: [ ‘$Data.selectmultidefault’, { ‘$const’: true } ],
lang: ‘js’ } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Data:
{ selectmultidefault:
{ ‘$function’:
{ body: ‘function SelectDefaultFunction(defaultArray, setArray){ return setArray.filter((item1) => defaultArray.some((item2) => item1.value === item2));}’,
args:
[ ‘$Data.selectmultidefault._v’,
[ { name: { ‘$const’: ‘1’ },
value: { ‘$const’: ‘1’ },
color: { ‘$const’: ‘#1976D2FF’ } },
{ name: { ‘$const’: ‘2’ },
value: { ‘$const’: ‘2’ },
color: { ‘$const’: ‘#1976D2FF’ } },
{ name: { ‘$const’: ‘3’ },
value: { ‘$const’: ‘3’ },
color: { ‘$const’: ‘#1976D2FF’ } },
{ name: { ‘$const’: ‘4’ },
value: { ‘$const’: ‘4’ },
color: { ‘$const’: ‘’ } } ] ],
lang: ‘js’ } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Data:
{ selectmodule:
{ ‘$function’:
{ body: ‘function(value, isMultiSelect) {if (!value) {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null} else if (typeof value === ‘string’){return isMultiSelect ? {_t:‘System.String[]’, _v: [ value ] } : value} else if (typeof value === ‘object’ && value._v != null && Array.isArray(value._v)) {return isMultiSelect ? value : ( value._v.length ? value._v[0] : {_t:‘System.String[]’, _v: [] } );} else {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null}}’,
args: [ ‘$Data.selectmodule’, { ‘$const’: false } ],
lang: ‘js’ } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘Contact’,
as: ‘Data.selectmodule’,
let:
{ localId:
{ ‘$convert’:
{ input: ‘$Data.selectmodule’,
to: { ‘$const’: ‘objectId’ },
onError: { ‘$const’: null } } } },
pipeline:
[ { ‘$match’: { ‘$expr’: { ‘$eq’: [ ‘$_id’, ‘$$localId’ ] } } },
{ ‘$project’: { Name: ‘$Data.name’ } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Data:
{ selectdefault:
{ ‘$function’:
{ body: ‘function(value, isMultiSelect) {if (!value) {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null} else if (typeof value === ‘string’){return isMultiSelect ? {_t:‘System.String[]’, _v: [ value ] } : value} else if (typeof value === ‘object’ && value._v != null && Array.isArray(value._v)) {return isMultiSelect ? value : ( value._v.length ? value._v[0] : {_t:‘System.String[]’, _v: [] } );} else {return isMultiSelect ? {_t:‘System.String[]’, _v: [] } : null}}’,
args: [ ‘$Data.selectdefault’, { ‘$const’: false } ],
lang: ‘js’ } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Data:
{ selectdefault:
{ ‘$filter’:
{ input:
{ ‘$const’:
[ { name: ‘1’, value: ‘1’, color: ‘#1976D2FF’ },
{ name: ‘2’, value: ‘2’, color: ‘’ },
{ name: ‘3’, value: ‘3’, color: ‘’ },
{ name: ‘4’, value: ‘4’, color: ‘’ } ] },
as: ‘item’,
cond: { ‘$eq’: [ ‘$$item.value’, ‘$Data.selectdefault’ ] } } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$addFields’:
{ Contact__MainId:
{ ‘$arrayElemAt’:
[ { ‘$filter’:
{ input: ‘$Relations’,
as: ‘r_Contact’,
cond:
{ ‘$and’:
[ { ‘$eq’: [ ‘$$r_Contact.Module’, { ‘$const’: ‘Contact’ } ] },
{ ‘$eq’: [ ‘$$r_Contact.IsMain’, { ‘$const’: true } ] } ] } } },
{ ‘$const’: 0 } ] } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘Contact’,
as: ‘Contact’,
let: { localId: { ‘$convert’: { input: ‘$Contact__MainId._id’, to: { ‘$const’: ‘objectId’ } } } },
pipeline:
[ { ‘$match’: { ‘$expr’: { ‘$eq’: [ ‘$_id’, ‘$$localId’ ] } } },
{ ‘$project’: { Name: ‘$Data.name’ } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$project’: { Contact__MainId: false, _id: true },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$addFields’:
{ Project__MainId:
{ ‘$arrayElemAt’:
[ { ‘$filter’:
{ input: ‘$Relations’,
as: ‘r_Project’,
cond:
{ ‘$and’:
[ { ‘$eq’: [ ‘$$r_Project.Module’, { ‘$const’: ‘Project’ } ] },
{ ‘$eq’: [ ‘$$r_Project.IsMain’, { ‘$const’: true } ] } ] } } },
{ ‘$const’: 0 } ] } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘Project’,
as: ‘Project’,
let: { localId: { ‘$convert’: { input: ‘$Project__MainId._id’, to: { ‘$const’: ‘objectId’ } } } },
pipeline:
[ { ‘$match’: { ‘$expr’: { ‘$eq’: [ ‘$_id’, ‘$$localId’ ] } } },
{ ‘$project’: { Name: ‘$Data.name’ } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$project’: { Project__MainId: false, _id: true },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘User’,
as: ‘Created_By’,
let: { localId: { ‘$convert’: { input: ‘$Created_By’, to: { ‘$const’: ‘objectId’ } } } },
pipeline:
[ { ‘$match’: { ‘$expr’: { ‘$eq’: [ ‘$$localId’, ‘$_id’ ] } } },
{ ‘$project’: { name: { ‘$concat’: [ ‘$FirstName’, ’ ', ‘$LastName’ ] } } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘User’,
as: ‘Modified_By’,
let: { localId: { ‘$convert’: { input: ‘$Modified_By’, to: { ‘$const’: ‘objectId’ } } } },
pipeline:
[ { ‘$match’: { ‘$expr’: { ‘$eq’: [ ‘$$localId’, ‘$_id’ ] } } },
{ ‘$project’: { name: { ‘$concat’: [ ‘$FirstName’, ’ ', ‘$LastName’ ] } } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$unwind’: { path: ‘$Children’, preserveNullAndEmptyArrays: true },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$addFields’: { Children: { ancestor_id: ‘$_graphlookupId’ } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘Contact’,
as: ‘Children.field_selectmodule’,
let:
{ localId:
{ ‘$convert’:
{ input: ‘$Children.Data.selectmodule’,
to: { ‘$const’: ‘objectId’ },
onError: { ‘$const’: ‘0’ } } } },
pipeline: [ { ‘$match’: { ‘$expr’: { ‘$eq’: [ ‘$_id’, ‘$$localId’ ] } } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Children:
{ Data:
{ selectmultimodule:
{ ‘$cond’:
[ { ‘$eq’:
[ { ‘$type’: [ ‘$Children.Data.selectmultimodule’ ] },
{ ‘$const’: ‘object’ } ] },
‘$Children.Data.selectmultimodule’,
{ ‘$const’: { _t: ‘System.String[]’, _v: [] } } ] } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘Contact’,
as: ‘Children.field_selectmultimodule’,
let: { details: ‘$Children.Data.selectmultimodule._v’ },
pipeline:
[ { ‘$match’:
{ ‘$expr’:
{ ‘$cond’:
[ { ‘$eq’: [ { ‘$type’: ‘$$details’ }, ‘array’ ] },
{ ‘$in’: [ { ‘$toString’: ‘$_id’ }, ‘$$details’ ] },
{} ] } } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘User’,
as: ‘Children.field_userselect’,
let:
{ localId:
{ ‘$convert’:
{ input: ‘$Children.Data.userselect’,
to: { ‘$const’: ‘objectId’ },
onError: { ‘$const’: ‘0’ } } } },
pipeline: [ { ‘$match’: { ‘$expr’: { ‘$eq’: [ ‘$_id’, ‘$$localId’ ] } } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Children:
{ field_userselect:
{ ‘$map’:
{ input: ‘$Children.field_userselect’,
as: ‘u’,
in:
{ _id: ‘$$u._id’,
IsActive: ‘$$u.IsActive’,
LastName: ‘$$u.LastName’,
FirstName: ‘$$u.FirstName’,
Profile: ‘$$u.Profile’,
Name: { ‘$concat’: [ ‘$$u.FirstName’, { ‘$const’: ’ ’ }, ‘$$u.LastName’ ] } } } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Children:
{ Data:
{ usermultiselect:
{ ‘$cond’:
[ { ‘$eq’:
[ { ‘$type’: [ ‘$Children.Data.usermultiselect’ ] },
{ ‘$const’: ‘object’ } ] },
‘$Children.Data.usermultiselect’,
{ ‘$const’: { _t: ‘System.String[]’, _v: [] } } ] } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$lookup’:
{ from: ‘User’,
as: ‘Children.field_usermultiselect’,
let: { details: ‘$Children.Data.usermultiselect._v’ },
pipeline:
[ { ‘$match’:
{ ‘$expr’:
{ ‘$cond’:
[ { ‘$eq’: [ { ‘$type’: ‘$$details’ }, ‘array’ ] },
{ ‘$in’: [ { ‘$toString’: ‘$_id’ }, ‘$$details’ ] },
{} ] } } } ] },
totalDocsExamined: 0,
totalKeysExamined: 0,
collectionScans: 0,
indexesUsed: [],
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’:
{ Children:
{ field_usermultiselect:
{ ‘$map’:
{ input: ‘$Children.field_usermultiselect’,
as: ‘u’,
in:
{ _id: ‘$$u._id’,
IsActive: ‘$$u.IsActive’,
LastName: ‘$$u.LastName’,
FirstName: ‘$$u.FirstName’,
Profile: ‘$$u.Profile’,
Name: { ‘$concat’: [ ‘$$u.FirstName’, { ‘$const’: ’ ’ }, ‘$$u.LastName’ ] } } } } } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$group’:
{ _id: ‘$Children.ancestor_id’,
doc: { ‘$first’: ‘$$ROOT’ },
Children: { ‘$push’: ‘$Children’ } },
maxAccumulatorMemoryUsageBytes: { doc: 0, Children: 0 },
totalOutputDataSizeBytes: 0,
usedDisk: false,
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$set’: { doc: { Children: ‘$Children’ } },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$replaceRoot’: { newRoot: ‘$doc’ },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$project’: { Data: { signature: false, panel: false }, _id: true },
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$facet’:
{ data:
[ { ‘$teeConsumer’: {},
nReturned: 0,
executionTimeMillisEstimate: 1 },
{ ‘$limit’: 25, nReturned: 0, executionTimeMillisEstimate: 1 } ],
count:
[ { ‘$teeConsumer’: {},
nReturned: 0,
executionTimeMillisEstimate: 0 },
{ ‘$group’: { _id: { ‘$const’: null }, count: { ‘$sum’: { ‘$const’: 1 } } },
maxAccumulatorMemoryUsageBytes: { count: 0 },
totalOutputDataSizeBytes: 0,
usedDisk: false,
nReturned: 0,
executionTimeMillisEstimate: 0 },
{ ‘$project’: { count: true, _id: false },
nReturned: 0,
executionTimeMillisEstimate: 0 } ] },
nReturned: 1,
executionTimeMillisEstimate: 1 } ],