Januka samaranyake
Januka samaranyake

Reputation: 2597

How to return distinct values for a field in Spring

I can retrieve the distinct values for a field using mongoDB query as,

db.context.distinct("context_name")

which results ["Restaurant", "School"]

My Mongo collection name is Context and a document looks like,

{
    "_id" : ObjectId("57ca8a45cadee6167c4d92ba"),
    "_class" : "com.something.webappmongo.domain.Context",
    "context_name" : "Restaurant"
}

Now I want to get result using this query from Spring framework (Spring Boot 1.4.0). I was using Jhipster.

How to do it in repository interface and resource class?

Upvotes: 2

Views: 1383

Answers (1)

rorschach
rorschach

Reputation: 2947

Create a Repository method "findDistinctBy[field]"

Upvotes: 2

Related Questions