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
You can see the differences of the usage of distinct between Spring Data JPA and Spring Data MongoDB here:
@Before
public void setUp() {
this.dave = customers.save(new Customer("Dave", "Matthews"));
this.carter2 = customers.save(new Customer("Carter", "Z"));
this.carter = customers.save(new Customer("Carter", "Beauford"));
}
@Test
public void distinctProjectsEntityIntoInterface() {
Collection<CustomerProjection> result = customers.findAllProjectedDistinctBy();
assertThat(result, hasSize(2));
}
distinct in spring data jpa
@Before
public void setUp() {
customers.deleteAll();
this.dave = customers.save(new Customer("Dave", "Matthews"));
this.carter2 = customers.save(new Customer("Carter", "Z"));
this.carter = customers.save(new Customer("Carter", "Beauford"));
}
@Test
public void distinctProjectsEntityIntoInterface() {
Collection<CustomerProjection> result = customers.findAllProjectedDistinctBy();
assertThat(result, hasSize(3));
}
distinct in spring data mongodb
where
interface CustomerProjection {
String getFirstname();
}