Lab: Using Cursor-like Stages - Getting wrong answer

Although this pipeline looks fine to me I’m still getting the wrong answer. I can’t find where I’m making a mistake.

const pipeLab = [
  {
    $match: {
      cast: { $elemMatch: { $exists: true } },
      countries: "USA",
      "tomatoes.viewer.rating": { $gte: 3 }
    }
  },
  {
    $addFields: { favorites: ["Sandra Bullock", "Tom Hanks", "Julia Roberts", "Kevin Spacey", "George Clooney"] }
  },
  {
    $project: {
      _id: false,
      title: true,
      cast: true,
      favorites: true,
      num_favs: {
        $size: { $setIntersection: ["$favorites", "$cast"] }
      }
    }
  },
  {
    $sort: {
      num_favs: -1,
      "tomatoes.viewer.rating": -1,
      title: -1
    }
  },
  {
    $limit: 25
  },
  {
    $skip: 24
  }
];

Hi @steevej
I finally figured out the root problem in my pipeline.

1 Like