Database

[{"_id":"","a":"","b":"","c":[{"_id":"","d":"","f":[{"orderDate":12345,"orderProfit":12},{"orderDate":67891,"orderProfit":12341},{"orderDate":23456,"orderProfit":474}]},{"_id":"","d":"","f":[{"orderDate":14232,"orderProfit":12222},{"orderDate":643532,"orderProfit":4343},{"orderDate":33423,"orderProfit":5555}]}]}]

Query

db.collection.find({$expr:{$sum:{"$map":{"input":"$c","as":"c","in":{$size:{"$filter":{"input":"$$c.f","cond":{$and:[{"$eq":[{"$max":"$$c.f.orderDate"},"$$this.orderDate"]},{$eq:["$$this.orderProfit",500]}]}}}}}}}})

Result