1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to MongoDB in Python

Exercise

Aggregating a few individuals' country data

The following query cursor yields birth-country and prize-affiliation-country information for three non-organization laureates:

cursor = (db.laureates.find(
    {"gender": {"$ne": "org"}},
    ["bornCountry", "prizes.affiliations.country"]
).limit(3))

Instructions

100 XP
  • Translate the above cursor cursor to an equivalent aggregation cursor, saving the pipeline stages to pipeline. Recall that the find collection method's "filter" parameter maps to the "$match" aggregation stage, its "projection" parameter maps to the "$project" stage, and the "limit" parameter (or cursor method) maps to the "$limit" stage.