Ticket: Faceted Search giving operation failure error

Hi All
Here is my pipeline being formed :
[{’$match’: {‘cast’: {’$in’: [‘Susan Sarandon’]}}}, {’$sort’: {‘tomatoes.viewer.numReviews’: -1}}, {’$facet’: {‘runtime’: [{’$bucket’: {‘groupBy’: ‘$runtime’, ‘boundaries’: [0, 60, 90, 120, 180], ‘default’: ‘other’, ‘output’: {‘count’: {’$sum’: 1}}}}], ‘rating’: [{’$bucket’: {‘groupBy’: ‘$metacritic’, ‘boundaries’: [0, 50, 70, 90, 100], ‘default’: ‘other’, ‘output’: {‘count’: {’$sum’: 1}}}}], ‘movies’: [{’$addFields’: {‘title’: ‘$title’}}]}}, ‘$skip’, {’$limit’: 20}]

My test cases are failing, getting following errors:

  1. pymongo.errors.OperationFailure: Results too large to sort, be more restrictive in filter
  2. pymongo.errors.OperationFailure: Error getting pipeline BSON docs field from doc

I am not able to figure out how to solve them. Can someone please guide me?

Here is the code change I did :
pipeline.append(facet_stage)
pipeline.append(skip_stage)
pipeline.append(limit_stage)

I have also removed pipeline =

If you didn’t solve it already, read all of the comments around the TODO.