Database

[{"_id":"c77c72de-edd8-4576-a72c-983cf93a0f31","DocumentId":"05240423067","Name":"John Doe","CreationDate":ISODate("0001-01-01T00:00:00.000+00:00"),"Score":5,},{"_id":"b5a7d404-a341-45dd-b875-864cd1e6bda2","DocumentId":"05240423067","Name":"John Doe","CreationDate":ISODate("2021-07-17T00:00:00.000+00:00"),"Score":2},{"_id":"9efddd23-4b6b-4e96-ab43-b24a080107db","DocumentId":"05240423067","Name":"John Doe","CreationDate":ISODate("2021-07-10T00:00:00.000+00:00"),"Score":2},{"_id":"f1a063a5-f9dd-4998-b6aa-df2071dd8677","DocumentId":"88313825863","Name":"Marcus Joseph","CreationDate":ISODate("2021-07-17T00:00:00.000+00:00"),"Score":2},{"_id":"e3262f8e-bd6a-49e8-abe5-c3c1a4e49900","DocumentId":"88313825863","Name":"Marcus Joseph","CreationDate":ISODate("0001-01-01T00:00:00.000+00:00"),"Score":1}]

Query

db.collection.aggregate([{"$group":{"_id":"$DocumentId","count":{"$sum":1},"docs":{"$push":"$$ROOT"}}},{/** if only 1, keep it*/"$match":{"$expr":{"$gt":["$count",1]}}},{/** find the doc to keep*/"$set":{"keepDoc":{"$reduce":{"input":"$docs","initialValue":{"Score":{"$minKey":1}},"in":{"$switch":{"branches":[{"case":{"$gt":["$$this.Score","$$value.Score"]},"then":"$$this"},{"case":{"$eq":["$$this.Score","$$value.Score"]},"then":{"$cond":[{"$gt":["$$this.CreationDate","$$value.CreationDate"]},"$$this","$$value"]}}],"default":"$$value"}}}}}},{/** get docs other than keepDoc*/"$project":{"_id":0,"expiredDocs":{"$filter":{"input":"$docs","cond":{"$ne":["$$this","$keepDoc"]}}}}},{"$unwind":"$expiredDocs"},{"$replaceWith":"$expiredDocs"}])

Result