我有一个类似下面的数据,我想按类型对这些数据进行分组,我使用的是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",
}
]我正在使用这种方法,但不会起作用。
GroupByResults<Queuing> results = mongoTemplate.group("queuing",
GroupBy.key("type"), Queuing.class);任何人都知道使用spring-data-mongodb进行分组的最好、最清晰的方法。
谢谢。
发布于 2017-02-17 21:41:03
这是group操作的正确语法。
GroupByResults<Queuing> results = mongoTemplate.group("queuing",
GroupBy.key("type").initialDocument("{}").reduceFunction("function(doc, prev) {}"),
Queuing.class);更多信息请点击此处http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo.group.example
https://stackoverflow.com/questions/42292255
复制相似问题