Java AggregationResults类型强制转换MongoDB+;弹簧数据+;聚集
我正在使用聚合从我的Spring数据应用程序中请求mongodb,当我得到结果时,我需要将其强制转换(或转换)到我自己的对象或类型,我不知道如何转换 这是我的密码Java AggregationResults类型强制转换MongoDB+;弹簧数据+;聚集,java,mongodb,spring-data,spring-data-mongodb,Java,Mongodb,Spring Data,Spring Data Mongodb,我正在使用聚合从我的Spring数据应用程序中请求mongodb,当我得到结果时,我需要将其强制转换(或转换)到我自己的对象或类型,我不知道如何转换 这是我的密码 AggregationResults aggregationResults = DBManager.getInstance().getMongoOperation().aggregate(aggregation, LevelEntity.class,Object.class); 我想要点像这样的 AggregationResults
AggregationResults aggregationResults = DBManager.getInstance().getMongoOperation().aggregate(aggregation, LevelEntity.class,Object.class);
我想要点像这样的
AggregationResults<LevelList> aggregationResults = DBManager.getInstance().getMongoOperation().aggregate(aggregation, LevelEntity.class,LevelList.class);
你能帮帮我吗
非常感谢使用如下
TypedAggregation<LevelList> aggregation=Aggregation.newAggregation(LevelList.class,
match, sortOp, skipOp, limitOp);
AggregationResults<LevelList> data = mongoTemplate.aggregate(aggregation,
COLLECTION_NAME, LevelList.class);
TypedAggregation聚合=聚合.newAggregation(LevelList.class,
火柴、索托、斯基普、利米托普);
AggregationResults data=mongoTemplate.aggregate(聚合,
集合名称,LevelList.class);
灾难你的回答并不完全正确,但给了我解决问题的钥匙,这就是我必须做的
TypedAggregation<LevelEntity> aggregation = Aggregation.newAggregation(LevelEntity.class,
userMatchOperation, dateMatchOperation, group(LevelEntity.DATE_FORMATTED_FIELD).push(ROOT).as(LevelByDate.ENTITY_NAME));
AggregationResults<LevelByDate> data = DBManager.getInstance().getMongoOperation().aggregate(aggregation, HappinessByDate.class);
TypedAggregation聚合=聚合.newAggregation(LevelEntity.class,
userMatchOperation、dateMatchOperation、组(LevelEntity.DATE\u格式的\u字段).push(ROOT).as(LevelByDate.ENTITY\u名称));
AggregationResults data=DBManager.getInstance().getMongoOperation().aggregate(聚合,HappinessByDate.class);
这是LevelByDate对象
@Document
public class LevelByDate {
public static final String ENTITY_NAME = "levelEntity";
@Id
private String id;
List<LevelEntity> levelEntity;
public LevelByDate() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<LevelEntity> getLevelEntity() {
return levelEntity;
}
public void setLevelEntity(List<LevelEntity> levelEntity) {
this.levelEntity = levelEntity;
}
}
@文档
公共类LevelByDate{
公共静态最终字符串实体\u NAME=“levelEntity”;
@身份证
私有字符串id;
上市公司;
公共LevelByDate(){
}
公共字符串getId(){
返回id;
}
公共无效集合id(字符串id){
this.id=id;
}
公共列表getLevelEntity(){
返回级实体;
}
公共无效setLevelEntity(列表levelEntity){
this.levelEntity=levelEntity;
}
}
非常感谢,
Kike.大灾变也许你不知道,但“我爱你”;)
@Document
public class LevelByDate {
public static final String ENTITY_NAME = "levelEntity";
@Id
private String id;
List<LevelEntity> levelEntity;
public LevelByDate() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<LevelEntity> getLevelEntity() {
return levelEntity;
}
public void setLevelEntity(List<LevelEntity> levelEntity) {
this.levelEntity = levelEntity;
}
}