Path collision at data._id remaining portion _id

Hi, I’m getting error at this stage

{
  _id: '$_id',
  program_name: {
    $first: '$program_name'
  },
  title: {
    $first: '$title'
  },
  description: {
    $first: '$description'
  },
  episode: {
    $first: '$episode'
  },
  seasons: {
    $first: '$seasons'
  },
  episodes: {
    $first: '$episodes'
  },
  dur: {
    $first: '$dur'
  },
  '4k': {
    $first: '$4k'
  },
  hlghdr: {
    $first: '$hlghdr'
  },
  progress: {
    $first: '$progress'
  },
  image: {
    $first: '$image'
  },
  watchlist: {
    $first: '$watchlist'
  },
  type: {
    $first: '$type'
  },
  data: {
    $push: '$data'
  },
  assets: {
    $push: '$assets'
  },
  count: {
    $first: '$count'
  },
  subscribed: {
    $first: '$subscribed'
  },
  plan: {
    $first: '$plan'
  },
  token: {
    $first: '$token'
  },
  usersettings: {
    $first: '$usersettings'
  }
}

Below is my aggregation pipeline.
Any help would be grateful.
Thanks

[{$match: {
  _id: ObjectId('5f168c368281ec7f46d0f35a'),
  type: 'program',
  status: 'active',
  schedule_on: {
    $lte: ISODate('2021-01-28T09:02:38.711Z')
  }
}}, {$addFields: {
  seasons: {
    $size: '$assets'
  }
}}, {$unwind: {
  path: '$assets',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  translations1: {
    $filter: {
      input: '$translations',
      as: 'translations',
      cond: {
        $and: [
          {
            $eq: [
              '$$translations.language',
              'en'
            ]
          }
        ]
      }
    }
  }
}}, {$addFields: {
  hlghdr: {
    $cond: {
      'if': {
        $in: [
          'hlg hdr',
          '$hdr'
        ]
      },
      then: true,
      'else': false
    }
  },
  dur: '$duration',
  program_name: {
    $arrayElemAt: [
      '$translations1.details.title',
      0
    ]
  },
  description: {
    $arrayElemAt: [
      '$translations1.details.description',
      0
    ]
  }
}}, {$project: {
  items: 0,
  updated_on: 0,
  updated_by: 0
}}, {$addFields: {
  images: {
    $cond: [
      {
        $ifNull: [
          '$images',
          false
        ]
      },
      '$images',
      []
    ]
  }
}}, {$unwind: {
  path: '$assets.details',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  'assets.details.videoid:': {
    $toObjectId: '$assets.details.video'
  }
}}, {$unwind: {
  path: '$assets.details',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  'assets.details.video': {
    $toObjectId: '$assets.details.video'
  }
}}, {$lookup: {
  from: 'assets',
  localField: 'assets.details.video',
  foreignField: '_id',
  as: 'data'
}}, {$unwind: {
  path: '$data',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  'data.watchlist': null,
  'data.progress': null,
  'data.4k': {
    $cond: {
      'if': {
        $eq: [
          '$data.assets_inputs.resolution',
          '4k'
        ]
      },
      then: true,
      'else': false
    }
  },
  'data.license_token': '$data.assets_inputs.license_token',
  'data.dur': '$data.duration',
  'data.translations1': {
    $filter: {
      input: '$data.translations',
      as: 'translations',
      cond: {
        $and: [
          {
            $eq: [
              '$$translations.language',
              'en'
            ]
          }
        ]
      }
    }
  }
}}, {$lookup: {
  from: 'users',
  localField: 'data._id',
  foreignField: 'watched.asset_id',
  as: 'users'
}}, {$addFields: {
  'data.hlghdr': {
    $cond: {
      'if': {
        $in: [
          'hlg hdr',
          '$data.hdr'
        ]
      },
      then: true,
      'else': false
    }
  },
  'data.dur': '$data.duration',
  'data.title': {
    $arrayElemAt: [
      '$data.translations1.details.title',
      0
    ]
  },
  'data.description': {
    $arrayElemAt: [
      '$data.translations1.details.description',
      0
    ]
  },
  'data.images': {
    $cond: [
      {
        $ifNull: [
          '$data.images',
          false
        ]
      },
      '$data.images',
      []
    ]
  }
}}, {$addFields: {
  'data.image': {
    $filter: {
      input: '$data.images',
      as: 'images',
      cond: {
        $and: [
          {
            $eq: [
              '$$images.aspect',
              '16:9'
            ]
          }
        ]
      }
    }
  },
  'data.episode_ai_id': '$data.episode'
}}, {$addFields: {
  'data.image': '$data.image.image',
  'data.episode': '$assets.details.episode',
  'data.season': '$assets.season'
}}, {$unwind: {
  path: '$users',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  'data.progress': {
    $filter: {
      input: '$users.watched',
      as: 'watched',
      cond: {
        $eq: [
          '$$watched.asset_id',
          '$data._id'
        ]
      }
    }
  },
  usersettings: {
    $cond: [
      {
        $ifNull: [
          '$users.usersettings',
          false
        ]
      },
      '$users.usersettings',
      null
    ]
  }
}}, {$unwind: {
  path: '$data.image',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  'data.image': {
    $cond: [
      {
        $ifNull: [
          '$data.image',
          false
        ]
      },
      '$data.image',
      null
    ]
  }
}}, {$unwind: {
  path: '$data.progress',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  'data.progress1': '$data.progress.progress'
}}, {$addFields: {
  'data.progress1': {
    $cond: [
      {
        $ifNull: [
          '$data.progress',
          false
        ]
      },
      '$data.progress.progress',
      0
    ]
  }
}}, {$unwind: {
  path: '$data.assets_inputs.metadata',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  'data.progress': '$data,progress1',
  'data.type': '$data.assets_inputs.metadata.category',
  subscribed: false,
  plan: 'free',
  token: '',
  'data.manifest': '$data.assets_inputs.manifest',
  'assets.details.videoidstring': {
    $toString: '$assets.details.video'
  }
}}, {$project: {
  'data.category': 0,
  'data.duration': 0,
  'data.resolution': 0,
  'data.translations': 0,
  'data.translations1': 0,
  'data.hdr': 0,
  'data.items': 0,
  'data.geo': 0,
  'data.tags': 0,
  'data.metadata': 0,
  'data.schedule_on': 0,
  'data.produced_on': 0,
  'data.updated_on': 0,
  'data.status': 0,
  'data.assets': 0,
  'data.friendlyname': 0,
  'data.images': 0,
  'data.progress1': 0
}}, {$sort: {
  'data.episode': 1
}}, {$sort: {
  'data.season': 1
}}, {$group: {
  _id: '$_id',
  program_name: {
    $first: '$program_name'
  },
  title: {
    $first: '$title'
  },
  description: {
    $first: '$description'
  },
  episode: {
    $first: '$episode'
  },
  seasons: {
    $first: '$seasons'
  },
  episodes: {
    $first: '$episodes'
  },
  dur: {
    $first: '$dur'
  },
  '4k': {
    $first: '$4k'
  },
  hlghdr: {
    $first: '$hlghdr'
  },
  progress: {
    $first: '$progress'
  },
  image: {
    $first: '$image'
  },
  watchlist: {
    $first: '$watchlist'
  },
  type: {
    $first: '$type'
  },
  data: {
    $push: '$data'
  },
  assets: {
    $push: '$assets'
  },
  count: {
    $first: '$count'
  },
  subscribed: {
    $first: '$subscribed'
  },
  plan: {
    $first: '$plan'
  },
  token: {
    $first: '$token'
  },
  usersettings: {
    $first: '$usersettings'
  }
}}, {$addFields: {
  episodes: '$data',
  currentepisode: {
    $filter: {
      input: '$assets',
      as: 'assets',
      cond: {
        $and: [
          {
            $eq: [
              '$$assets.details.videoidstring',
              '5ed5081b46c9074616122f79'
            ]
          }
        ]
      }
    }
  }
}}, {$unwind: {
  path: '$currentepisode',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  currentepisodeid: {
    $filter: {
      input: '$episodes',
      as: 'episodes',
      cond: {
        $and: [
          {
            $eq: [
              '$$episodes._id',
              ObjectId('5ed5081b46c9074616122f79')
            ]
          }
        ]
      }
    }
  }
}}, {$unwind: {
  path: '$currentepisodeid'
}}, {$addFields: {
  'currentepisodeid.episode_ai_id': {
    $toObjectId: '$currentepisodeid.episode_ai_id'
  }
}}, {$lookup: {
  from: 'assets_inputs',
  localField: 'currentepisodeid.episode_ai_id',
  foreignField: '_id',
  as: 'currentepisode_assets_inputs'
}}, {$unwind: {
  path: '$currentepisode_assets_inputs',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  'currentepisode_assets_inputs.sprites': {
    $ifNull: [
      '$currentepisode_assets_inputs.sprites',
      false
    ]
  },
  'currentepisode_assets_inputs.manifest': {
    $ifNull: [
      '$currentepisode_assets_inputs.manifest',
      false
    ]
  }
}}, {$redact: {
  $cond: {
    'if': {
      $and: [
        {
          $eq: [
            '$currentepisode_assets_inputs.sprites',
            false
          ]
        },
        {
          $eq: [
            '$currentepisode_assets_inputs.manifest',
            false
          ]
        }
      ]
    },
    then: '$$PRUNE',
    'else': '$$DESCEND'
  }
}}, {$addFields: {
  count: {
    $add: [
      '$currentepisode.details.episode',
      1
    ]
  },
  season: '$currentepisode.season'
}}, {$addFields: {
  next: {
    $filter: {
      input: '$assets',
      as: 'assets',
      cond: {
        $and: [
          {
            $eq: [
              '$$assets.details.episode',
              '$count'
            ]
          },
          {
            $eq: [
              '$season',
              '$$assets.season'
            ]
          }
        ]
      }
    }
  }
}}, {$unwind: {
  path: '$next',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  next: {
    $filter: {
      input: '$data',
      as: 'data',
      cond: {
        $and: [
          {
            $eq: [
              '$$data._id',
              '$next.details.video'
            ]
          }
        ]
      }
    }
  },
  currentepisode: {
    $filter: {
      input: '$data',
      as: 'data',
      cond: {
        $and: [
          {
            $eq: [
              '$$data._id',
              '$currentepisode.details.video'
            ]
          }
        ]
      }
    }
  }
}}, {$unwind: {
  path: '$currentepisode',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  title: '$currentepisode.title',
  description: '$currentepisode.description'
}}, {$unwind: {
  path: '$currentepisode_assets_inputs.sprites',
  preserveNullAndEmptyArrays: true
}}, {$addFields: {
  title: '$currentepisode.title',
  description: '$currentepisode.description',
  episode: {
    $subtract: [
      '$count',
      1
    ]
  },
  dur: '$currentepisode.dur',
  '4k': '$currentepisode.4k',
  hlghdr: '$currentepisode.hlghdr',
  progress: '$currentepisode.progress',
  image: '$currentepisode.image',
  watchlist: '$currentepisode.watchlist',
  type: '$currentepisode.type',
  manifest: '$currentepisode_assets_inputs.manifest',
  token: '$currentepisode_assets_inputs.license_token',
  spriteOutputPath: {
    $arrayElemAt: [
      '$currentepisode_assets_inputs.sprites.outputs.outputPath',
      0
    ]
  },
  spriteName: '$currentepisode_assets_inputs.sprites.spriteName',
  vttName: {
    $concat: [
      {
        $arrayElemAt: [
          '$currentepisode_assets_inputs.sprites.outputs.outputPath',
          0
        ]
      },
      '$currentepisode_assets_inputs.sprites.vttName'
    ]
  },
  license_server: {
    fairplay: {
      acquisition_url: 'https://drm-fairplay-licensing.axtest.net/AcquireLicense',
      certificate_url: 'https://vtb.axinom.com/FPScert/fairplay.cer'
    },
    widevine: {
      acquisition_url: 'https://drm-widevine-licensing.axtest.net/AcquireLicense'
    },
    playready: {
      acquisition_url: 'https://drm-playready-licensing.axtest.net/AcquireLicense'
    }
  },
  cdn: [
    'https://travelxp.s.llnwi.net'
  ],
  device: '',
  manifesttype: ''
}}, {$project: {
  data: 0,
  assets: 0,
  count: 0,
  currentepisode: 0,
  'episodes.assets_inputs': 0,
  currentepisodeid: 0,
  currentepisode_assets_inputs: 0,
  'episodes.license_token': 0
}}]

Hi @Sudarshan_Chavan,

In order to better help you with this issue it will be best o get a sample document that fails this aggregation so we could reproduce it.

What is the full error and with what tool are you getting it?

Best regards,
Pavel

Hi @Pavel_Duchovny,

There was typo in query.

There should have been dot instead of comma in '$data,progress1’Thanks for help.

{$addFields: {
  'data.progress': '$data,progress1',  <- This line
  'data.type': '$data.assets_inputs.metadata.category',
  subscribed: false,
  plan: 'free',
  token: '',
  'data.manifest': '$data.assets_inputs.manifest',
  'assets.details.videoidstring': {
    $toString: '$assets.details.video'
  }
1 Like