Database

[{"key":1,"dates":[{"id":1,"startDate":"20220512","endDate":"20220517"},{"id":2,"startDate":"20220701","endDate":"20220705"}]},{"key":2,"dates":[{"id":3,"startDate":"20220501","endDate":"20220505"}]}]

Query

db.collection.aggregate([{$project:{result:{$filter:{input:"$dates",as:"item",cond:{$and:[{$gte:[{$toInt:"$$item.startDate"},20220512]},{$lte:[{$toInt:"$$item.endDate"},20220517]}]}}}}}])

Result