Database

[{notificationClass:"category",sourceObjectIdentifier:1,notificationType:"a",creationTime:ISODate("2023-06-01")},{notificationClass:"category",sourceObjectIdentifier:1,notificationType:"a",creationTime:ISODate("2023-06-02")},{notificationClass:"category",sourceObjectIdentifier:1,notificationType:"a",creationTime:ISODate("2023-06-03")},{notificationClass:"category",sourceObjectIdentifier:1,notificationType:"a",creationTime:ISODate("2023-06-04")},{notificationClass:"category",sourceObjectIdentifier:1,notificationType:"b",creationTime:ISODate("2023-05-01")},{notificationClass:"category",sourceObjectIdentifier:1,notificationType:"b",creationTime:ISODate("2023-05-02")},{notificationClass:"category",sourceObjectIdentifier:1,notificationType:"c",creationTime:ISODate("2023-05-10")},{notificationClass:"category",sourceObjectIdentifier:1,notificationType:"c",creationTime:ISODate("2023-06-11")},{notificationClass:"category",sourceObjectIdentifier:1,notificationType:"c",creationTime:ISODate("2023-06-11")}]

Query

db.collection.aggregate([{$setWindowFields:{partitionBy:{sourceObjectIdentifier:"sourceObjectIdentifier",notificationType:"$notificationType"},sortBy:{creationTime:-1},output:{rank:{$rank:{}},}}},{$match:{rank:{$gt:1}}}])

Result