我正在使用MongoDD处理Spring,目标是从查询中获取结果并将其绘制到谷歌地图中。在这里,我已经完成聚合以获取字段的计数并匹配它,但是在迭代AggregationResults时我得到空值
这是我的代码:
GroupOperation groupByState =Aggregation. group("State_1").sum("NPI").as("doctor_count");
MatchOperation filterStates = Aggregation.match(new Criteria("doctor_count").lt(10000000));
SortOperation sortByCntDesc = Aggregation.sort(new Sort(Direction.DESC, "doctor_count"));
Aggregation aggregation =Aggregation.newAggregation( groupByState, filterStates, sortByCntDesc);
AggregationResults<FilterFieldsModelBean> result = mongoTemplate.aggregate(aggregation, "doctor_details", FilterFieldsModelBean.class);
list = result.getMappedResults();
System.out.println("list: "+list.size());
for(FilterFieldsModelBean bean:list){
System.out.println(">> "+bean.getDoctor_count());
System.out.println(">> "+bean.getCity());
System.out.println(">> "+bean.getState());
System.out.println(">> "+bean.getNPI());
System.out.println(">> "+bean.getFirst_Name());
}
我需要将所有字段映射到bean类中。它有各自的Getters和Setters。 FilterFieldsModelBean.java
@Id
private String id;
private String NPI;
private String PAC_ID;
private String Professional_Enrollment_ID;
@Field("Last_Name")
private String Last_Name;
@Field("First_Name")
private String First_Name;
@Field("Middle_Name")
private String Middle_Name;
@Field("Gender_1")
private String Gender;
@Field("Medical_school_name")
private String Medical_school_name;
@Field("Primary_specialty")
private String Primary;
@Field("City_1")
private String City;
@Field("State_1")
private String States;
@Field("Graduation_year")
private String Graduation_year;
private String Zip_Code;
private String Phone_Number;
private String Organization_legal_name;
private String Group_Practice_PAC_ID;
@Field("latitude")
private String latitude;
@Field("longitude")
private String longitude;
private String Doctor_count;
纠正我错在哪里。帮助得到赞赏:)