Using dot notation in the filter stage doesn't work

I am trying to filter Albums object in the last project stage of aggregation as the below

      $project: {
        Artist: 1,
        Albums: {
            input : "$Albums",
            as : "album",
            cond : {
              $in: [{"$ifNull":[{$first: "$$album.Sales.Total_Sales.Date"},-1]},dateArray]

The weird thing here is I try to use the array index first instead of $first operator like below

  $in: [{"$ifNull":["$$album.Sales.Total_Sales.0.Date",-1]},dateArray]


$in: ["$$album.Sales.Total_Sales.0.Date",dateArray]

and it doesn’t work like that . I have to specifically use the $first operator instead of array index. What am I missing here? Is there any documentation for this behaviour?

Hi :wave: @Kyaw_Zayar_Tun,

Could you please provide more details on why an array index instead of the $first and what the workflow of the aggregation pipeline entails?

However, in order to understand the requirement better, could you please share some information to replicate in my local environment?

  • Sample document from MongoDB dataset
  • MongoDB version used
  • Expected result documents