Filter out the docs in the nested array with generic key structure

I need some help with the aggregation. I want to filter out the docs based on the provided date and bookName . The docs need to be sorted as well.

What I have done:

  • The docs are currently sorted, however I am hardcoded the date field logic. It is not necessarily in the first position of the array.
  • able to filter out by the date but not bookName

Kindly take a look, Mongo playground