find distinct embedded documents from the document using Spring Data Mongo?

安稳与你 提交于 2019-12-01 14:48:55

I was able to solve this issue by using latest version of Spring Boot Mongo and using Spring Boot library v 2.1.4.RELEASE.

More details can be referred from here: https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo-template.query.distinct

List<Object> object = mongoTemplate.query(Person.class).distinct("hobbies").all();
    for (Object object2 : object) {
        Hobbies hobbies = (Hobbies) object2;
        System.out.println(hobbies);
    }

This works very well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!