在Spring Data MongoDB中与众不同 [英] Distinct in Spring Data MongoDB
本文介绍了在Spring Data MongoDB中与众不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人尝试使用Spring Data for Mongo
将distinct
合并到查询中.如果您有示例,请张贴.我应该在哪里以及如何添加distinct flag
?
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 should I include the distinct flag
?
链接到Spring Data Mongo示例-Example 4.4. Query creation from method names
// Enables the distinct flag for the query
List<Person> findDistinctPeopleByLastnameOrFirstname(String lastname, String firstname);
List<Person> findPeopleDistinctByLastnameOrFirstname(String lastname, String firstname);
推荐答案
自发布此问题以来,地段已更改.随着这个问题不断出现,回答了我自己的问题.
Lot has changed since this question was posted. Answering my own question as this question keeps popping up.
从3.0
及更高版本开始提供支持
Support is there since 3.0
and higher
public DistinctIterable<String> getUniqueTask() {
return mongoTemplate.getCollection(TABLE).distinct("FIELD", String.class);
}
侧面注意:您甚至可以向该查询添加过滤器/正则表达式.阅读文档.如果找不到,请ping,将发布答案.
这篇关于在Spring Data MongoDB中与众不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文