Database

[{"id_1":120,"id_2":-1,"info":"dont"},{"id_1":120,"id_2":444,"info":"show"},{"id_1":123,"id_2":-1,"info":"test"},{"id_1":124,"id_2":-1,"info":"hello"},{"id_1":125,"id_2":-1,"info":"world"},{"id_1":125,"id_2":123,"info":"oh wait"},{"id_1":126,"id_2":-1,"info":"help"},{"id_1":126,"id_2":201,"info":"me"},{"id_1":127,"id_2":-1,"info":"sql"},{"id_1":127,"id_2":206,"info":"hell"},]

Query

db.collection.aggregate([{"$match":{"id_1":{"$in":[123,124,125,126,127]},"id_2":{"$in":[-1,123,201,206]}}},{$setWindowFields:{partitionBy:"$id_1",sortBy:{id_2:1},output:{max:{$max:"$id_2",window:{documents:["unbounded","unbounded"]}}}}},{"$match":{$expr:{"$eq":["$id_2","$max"]}}},{"$unset":"max"}])

Result