0

我对 spring boot 和 mongoDB 都是新手。有映射的集合,我必须使用连接来获取数据。收藏一:

@Document("userResponses")
public class UserResponse { 
private String moduleName;
private String subModule;
private int botResponseId;
private String botResponseType;
private HashMap<String,String> responseData;
private String sentAtInstant;
private String userId; 
// setters and getters
}

收藏2:

@Document("questions")
public class Question implements ResponseData{

@Id
private int id;
private String text;
private String shortText;
private String textStyleClass;
private List<Option> options;
private Map<String,Object> metaInfo;
private Map<String,Object> optionsInfo;
private String insLogin;
private String updLogin;
private String insTs;
private String updTs;
//setters and getters
}

我的代码:

Criteria criteria = new Criteria();
MatchOperation match = Aggregation.match(criteria); 
LookupOperation lookup = Aggregation.lookup("userResponses",
            "botResponseId", 
            "_id", 
            "questions"); 

TypedAggregation<UserResponse> agg =Aggregation.newAggregation(UserResponse.class,match, lookup);

AggregationResults<UserResponse> res = mongoTemplate.aggregate(agg, UserResponse.class);
List<UserResponse> res1 = res.getMappedResults();

它只给了我 userResponse 集合,不知何故它没有给我合并的集合,即 userResponse 和 questions 集合。

4

0 回答 0