Distinct in Spring Data MongoDB

前端 未结 7 1758
小鲜肉
小鲜肉 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:40

    You can do it with the help of MongoOperations -

    Query query = new Query(where("field").in(requestIds));
    List result =  mongoOperations.findDistinct(query, "fieldName",                                                                              "collectionName",                                                                    String.class);
    

    With MongoTemplates -

    mongoTemplate.getCollection("collectionName").distinct("filedName", requestIds);
    

提交回复
热议问题