Distinct in Spring Data MongoDB

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

    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();
    } 
    
    0 讨论(0)
提交回复
热议问题