关于MongoDB中两张表的查询

图片说明
我需要根据一级和二级类别的name查询应用程序表的数据。但每次查询的都有用两个while循环,
DBCursor cursor1=null;
DBCursor cursor=this.dao.getDBCursor(offset, pageSize, db, "thirdCategory", sort);
DBObject query1 = new BasicDBObject();
while (cursor.hasNext()) {
@SuppressWarnings("unchecked")
Map map1 = cursor.next().toMap();
System.out.println(map1);
if(map1!=null){
query1.put("categoryId",map1.get("categoryId"));
cursor1=this.dao.getDBCursor(offset, pageSize, query1, "ucApp", sort);
while (cursor1.hasNext()) {
@SuppressWarnings("unchecked")
Map map2 = cursor1.next().toMap();

if(map2!=null){
map2.putAll(map1);
list.add(map2);
}
}
}
}
Map map3 = new HashMap();
map3.put("total", cursor1 == null ? 0 : cursor1.count());
map3.put("data", list);
return map3;
导致我分页不行。