I'm trying to get the list of distinct items by a specific field (userId). Currently I'm using this kind of approach to get records from MongoDB using ReactiveCrudRepository
. Additionally, I want this result to be further filtered and get only the distinct items.
How to do this?
@Query(value = "{$and :[{'submitTime':{$ne:null}}, {'gameId': :#{#gameId}} ]}", sort = "{'score': -1, 'timeTaken': 1, 'submitTime': 1}")
Flux<Play> getWinners(@Param("gameId") String gameId, Pageable pageable);
My Play
object is like this:
@Document(value = "play")
@Builder
public class Play {
@Id
private String id;
private String gameId;
private int score;
private String userId;
private LocalDateTime submitTime;
private long timeTaken;
}