Final: Question 7 Help

I think I’m almost there, but I get the answer SkyTeam but it’s incorrect

{ "_id" : "SkyTeam", "allCount" : 4 } // Wrong answer
{ "_id" : "OneWorld", "allCount" : 10 }

Here is my pipeline, can I know where I’m going wrong.

[
  {
    '$match': {
      'src_airport': {
        '$in': [
          'JFK', 'LHR'
        ]
      }, 
      'dst_airport': {
        '$in': [
          'JFK', 'LHR'
        ]
      }
    }
  }, {
    '$addFields': {
      'airline': '$airline.name'
    }
  }, {
    '$lookup': {
      'from': 'air_alliances', 
      'localField': 'airline', 
      'foreignField': 'airlines', 
      'as': 'alliance'
    }
  }, {
    '$match': {
      'alliance': {
        '$elemMatch': {
          '$exists': 1
        }
      }
    }
  }, {
    '$project': {
      'airline': 1, 
      'src_airport': 1, 
      'dst_airport': 1, 
      'alliance': {
        '$arrayElemAt': [
          '$alliance', 0
        ]
      }
    }
  }, {
    '$group': {
      '_id': '$alliance.name', 
      'allCount': {
        '$sum': 1
      }
    }
  }
]

Hi @Rakshith_79674, welcome to the community.
Congratulations, yes you are very close to completing the course.
As far as I can see, you are trying to eliminate the empty array containing documents in the $match stage, however, your second $match stage is not actually looking for empty arrays, you might want to update the $match stage by using some other array operators to determine whether the array is empty or not.

I hope that helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

1 Like

The question reads as

has the most unique carriers(airlines)

Would the most be the one with the bigger allCount rather than the one with the smaller?

1 Like

I tried to group with airline._id it worked.
Thank you
@steevej
@SourabhBagrecha

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.