ATTENTION
There is a second initialization of the variable pipeline after the TODO comment that is causing a loss of code provoking unwanted results:
# TODO: Faceted Search
# Add the necessary stages to the pipeline variable in the correct order.
pipeline = []
It must be commented or deleted as to keep the $match filter definition some lines above:
if "cast" in filters:
pipeline.extend([{
"$match": {"cast": {"$in": filters.get("cast")}}
}, {
"$sort": {sort_key: DESCENDING}
}])
else:
raise AssertionError("No filters to pass to faceted search!")
Jaime Rozo