“ LookupOperation”始终提供第一条记录数据

时间:2018-12-05 04:27:03

标签: java mongodb spring-boot

问题:总是从第二张表(mongo文档)获得第一条记录。

环境:

UserCompany文档

@Document(collection = "userComp")
public class UserCompany {
    @Id
    private String id;
    @Field("comp_id")
    private String companyId;
    ...
    ...
    getters/setters

}  

用户文档

@Document(collection = "user")
public class User {
    @Id
    private String id;
    @Field("fname")
    private String firstName;
    ....
    ....
    getters/setters
}

CompanyUsersDTO类

public class CompanyUsersDTO {
    private String id;
    private String user_id;
    ...
    private User userDTO;

    getters/setters
}

我正在调用a

public void getUsersDetails(String companyId) {
    LookupOperation lookupOperation = LookupOperation.newLookup().from("user").localField("userId").foreignField("id").as("userDTO"); //todo
    Aggregation aggregation = newAggregation(Aggregation.match(Criteria.where("comp_id").is(companyId)), lookupOperation);
    List<CompanyUsersDTO> userResult = mongoTemplate.aggregate(aggregation, "userComp", CompanyUsersDTO.class).getMappedResults();
    ...
    ...
}

预期结果集: 获取UserCompany结果集,并根据(UserCompany-> userId)

获取正确的用户详细信息。

在这里,我总是首先在用户表(mongo document)中重新编码详细信息。似乎在我的“ LookupOperation”中有问题。

感谢您的建议/解决方案。

0 个答案:

没有答案