我是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));
});