Spring - mongodb - aggregation - The 'cursor' option is required

后端 未结 3 483
不知归路
不知归路 2021-01-12 17:26

Executing the following aggregation pipeline:

public void getMostLikedItems () {
        UnwindOperation unwind = Aggregation.unwind(\"favoriteItems\");
             


        
3条回答
  •  自闭症患者
    2021-01-12 17:59

    You can provide outputmode as cursor as providing a cursor is mandatory

    List list = new ArrayList();
    list.add(unwind.toDBObject(Aggregation.DEFAULT_CONTEXT));
    list.add(group.toDBObject(Aggregation.DEFAULT_CONTEXT));
    list.add(sort.toDBObject(Aggregation.DEFAULT_CONTEXT));
    
    DBCollection col = mongoTemplate.getCollection("users");
    
    Cursor cursor = col.aggregate(list, AggregationOptions.builder().allowDiskUse(true).outputMode(OutputMode.CURSOR).build());
    
    List result = new ArrayList();
    
    while(cursor.hasNext()) {
         DBObject object = cursor.next();
         result.add(new AggregationResultVO(object.get("aggregationResultId").toString()));
    }
    

提交回复
热议问题