Wait, I just noticed that this returns what I need:
Aggregation aggregation = newAggregation( group("$key") .max("$timestamp").as("timestamp") .first("$value").as("value") );
The only difference is that “key” is called “_id” in the output. Not sure if one can rename it.
Is this an inefficient way of solving the problem?