Distinct in Spring Data MongoDB

前端 未结 7 1779
小鲜肉
小鲜肉 2021-01-04 00:28

Has anyone tried incorporating distinct in their query using Spring Data for Mongo. If you have an example can you please post it. Where and how sh

7条回答
  •  死守一世寂寞
    2021-01-04 00:36

    Lot has changed since this question was posted. Answering my own question as this question keeps popping up.

    Support is there since 3.0 and higher

    public DistinctIterable getUniqueTask() {
        return mongoTemplate.getCollection(TABLE).distinct("FIELD", String.class);
    }
    

    Side Note: You can even add filters/regex to this query. Read docs. If you cannot find, ping, will post the answer.

提交回复
热议问题