How to write projection to get nested object only from collection schema

A aggregation with $match, $unwind and repalce root operation could be the solution here.

  • $match to find just records with name: “ABC”
  • $unwind the outerArr data to get each item in an individual document
  • $match to filter out items that satisfy outerID criteria
  • $unwind the innerArr data to get each item in an individual document
  • $match to filter out items that satisfy date criteria
  • $replaceRoot to move the data within the innerArr field up to the root

Build the aggregation pipeline stage by stage so you can track whats going on.

You may also want to think about changing the date to a date object as opposed to string…