問題使用spring boot和mongodb檢索完整和不完整配置文件的用戶數的最佳方法是什麼?
1)我必須顯示具有不完整和完整配置文件的總用戶數。
2)不完整的配置文件是那些將有4個字段的字符串類型。 除此之外,全部都是完整配置文件。
下面是我的模型類字段
@Id
private String id;
private String[] imageIds;
private String concerns;
private String summary;
private String likings;
private String occupation;
private String religion;
private String education;
private String height;
@GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)
private double[] location;
private INTERESTS[] interests;
private String fcmId;
private List connections;
private List declined;
private List pending;
代碼我已經寫:
1)在MySQL中我可以申請直接查詢它類似於
a)選擇計數(*)from X其中a是NULL或b IS NULL - > ForIncompleteProfiles
b)從X中選擇count(*),其中IS NOT NULL或b IS NOT NULL - >對於CompleteProfiles
但在這裏,
2)我可以使用的findAll()方法來檢索所有用戶在用戶的名單,然後再檢查使用每個用戶如果user.getA()或user.getB()中的任何一個字段爲空.IF是,計數爲未完成的配置文件否則計爲完整的配置文件。
然後,我可以在一個HashMap返回這兩個數的一個frontEndUSer
任何人都可以指導我,如果這是一個正確的方法,如果不是如何使用做更有效的方式和有效途徑Spring引導和MongoData存儲庫。
下面是我爲同一
@RequestMapping(value = "/showprofiles", method = RequestMethod.GET)
public Map showProfiles(HttpServletResponse response) {
int pageSize=2000;
Page<User> users=null;
int page=0;
int countInComplete=0;
int countComplete=0;
Map hm=null;
users = userService.getAllUsers(new PageRequest(page,pageSize));
do {
users = userService.getAllUsers(new PageRequest(page,pageSize));
for (User user : users) {
if (user.getName() == null || user.getGender() == null || user.getInterests() == null || user.getImageIds() == null) {
countInComplete++;
}
else{
countComplete++;
}
}
page++;
}while (users.hasNext());
hm=new HashMap();
hm.put("countComplete",countComplete);
hm.put("countInComplete",countInComplete);
return hm;
}