需要帮助调整我的mongotemplate查询,因​​为它需要6-7秒

时间:2017-12-20 17:18:57

标签: json spring mongotemplate

我是MongoDB的新手。以下查询需要很长时间 - 我如何调整它以便获取记录列表而不是多次访问MongoDB?

List newList = new ArrayList ();
listDetails.forEach(query -> {
    BasicDBObject  criteria1 = new BasicDBObject();
    criteria1.put("_id", query.getId());
    BasicDBObject criteria2 = new BasicDBObject();
    criteria2 .put("$elemMatch", new BasicDBObject("ID", query.getEmpId()));
    BasicQuery basicQuery = new BasicQuery(criteria1, new BasicDBObject("empName", criteria2));
    newList.add(mongoTemplate.findOne(basicQuery, ClassName.class));
}); 

0 个答案:

没有答案