我使用聚合从 Spring 数据应用程序中询问 mongodb,当我得到结果时,我需要将其转换(或转换)为我自己的对象或类型,但我不知道如何操作。
这是我的代码
AggregationResults aggregationResults = DBManager.getInstance().getMongoOperation().aggregate(aggregation, LevelEntity.class,Object.class);
我想要类似的东西
AggregationResults<LevelList> aggregationResults = DBManager.getInstance().getMongoOperation().aggregate(aggregation, LevelEntity.class,LevelList.class);
它给了我这些信息
{
"_id" : {
"date" : "24/03/2015"
},
"levels" : [
{
"_id" : ObjectId("54f8627071fdac0ec132b4e5"),
"_class" : "org.xxxxxxxxxxx.persistence.model.impl.LevelEntity",
"user" : {
"_id" : ObjectId("54da19ce71fd56a173a3451a"),
...
...
...
},
"level" : 4,
"date" : ISODate("2015-03-24T14:04:32.830Z"),
"dateFormatted" : "24/03/2015"
},
{
"_id" : ObjectId("54f8627071fdac0ec132b4f4"),
"_class" : "org.xxxxxxxxxxx.persistence.model.impl.LevelEntity",
"user" : {
"_id" : ObjectId("54e34bd671fde9071569650c"),
...
...
...
},
"level" : 3,
"date" : ISODate("2015-03-24T14:04:32.866Z"),
"dateFormatted" : "24/03/2015"
}
]
}
你能帮帮我吗????
非常感谢
最佳答案
使用方法如下
TypedAggregation<LevelList> aggregation=Aggregation.newAggregation(LevelList.class,
match, sortOp, skipOp, limitOp);
AggregationResults<LevelList> data = mongoTemplate.aggregate(aggregation,
COLLECTION_NAME, LevelList.class);
关于java - AggregationResults 类型转换 MongoDB + Spring 数据 + 聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28896878/