0

I have a data like below, and I want to group that data by the type, I'm using spring-data-mongodb .

[
    {
        "_id" : ObjectId("58a5518aace6132a88309d98"),
        "type" : "SMS",
    },
    {
        "_id" : ObjectId("58a5518bace6132a88309d99"),
        "type" : "PUSH_NOTIFICATION",
    },
    {
        "_id" : ObjectId("58a5519aace6132a0094d7df"),
        "type" : "SMS",
    },
    {
        "_id" : ObjectId("58a5519aace6132a0094d7e0"),
        "type" : "PUSH_NOTIFICATION",
    }
]

I'm using this method and won't work.

GroupByResults<Queuing> results = mongoTemplate.group("queuing",
                GroupBy.key("type"), Queuing.class);

Anyone know the best and clear way to do this grouping using spring-data-mongodb.

Thanks.

1 Answer 1

2

This is the correct syntax for group operation.

GroupByResults<Queuing> results = mongoTemplate.group("queuing",
            GroupBy.key("type").initialDocument("{}").reduceFunction("function(doc, prev) {}"),
            Queuing.class);

More information here http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo.group.example

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.