Get startedGet started for free

Embedding aggregation expressions

The $expr operator allows embedding of aggregation expressions in a normal query (or in a $match stage). Which of the following expressions counts the number of laureate documents with string-valued bornCountries when passed to db.laureates.count_documents?

You can assume (and check!) that the following is true:

assert all(isinstance(v, str) for v in db.laureates.distinct("bornCountry"))

This exercise is part of the course

Introduction to MongoDB in Python

View Course

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise