1 year ago

#92706

test-img

Ishani Samaraweera

MongoDB Morphia distinct

public Collection<OwnerDetail> getAllOwners() {
    final MorphiaCursor<Listing> listings = datastore.find(Listing.class)
            .iterator(new FindOptions()
                    .projection().include("ownerDetail"));

    Map<String, OwnerDetail> map = new HashMap<>();

    while (listings.hasNext()) {
        final Listing next = listings.next();
        if (next.getOwnerDetail() != null) {
            map.put(next.getOwnerDetail().getEmail(), next.getOwnerDetail());
        }
    }
    return map.values();
}

I want to remove java code that distinct values by email and handle it by mongodb morphia. How can I do that?

java

mongodb

morphia

0 Answers

Your Answer

Accepted video resources