DBCollection coll = mongoTemplate.getCollection("DBname");
DBObject limit = new BasicDBObject("$limit","value");
DBObject skip = new BasicDBObject("$skip", "value");
DBObject snum = new BasicDBObject("num","value");
DBObject sort = new BasicDBObject("$sort",snum);
//sort 먼저 한후 limit 로 가져올행 skip 할 행
AggregationOutput output = coll.aggregate(sort,limit, skip);
for(DBObject obj : output.results()){
Article art = new Article();
String num = obj.get("value").toString();
String title = obj.get("value").toString();
String content = obj.get("value").toString();
}
limit 를 출력하면
{ "$limit" : "9" } 9는 임의의 value
skip를 출력하면
{ "$skip" : "0" } 9는 임의의 value
sort 를 출력하면
{ "$sort" : { "num" : -1 } } 9는 임의의 value
DBObject 는 하나에 {} 안에 - 변수 : 값 이 들어 간다 , { "$변수" : "값"}
DBObject 안에 DBObject snum 변수를 sort의 변수로 사용할시 { "$변수" : {"$변수" : "값" } }