[英]How do I GroupBy in Spring Data Mongodb without Aggregation?
我有一個像下面這樣的數據,我想按類型對數據進行分組,我正在使用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
分組的最佳清晰方法。
謝謝。
這是用於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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.