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

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

Executing the following aggregation pipeline:

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


        
3条回答
  •  走了就别回头了
    2021-01-12 17:52

    From the docs.

    MongoDB 3.4 deprecates the use of aggregate command without the cursor option, unless the pipeline includes the explain option. When returning aggregation results inline using the aggregate command, specify the cursor option using the default batch size cursor: {} or specify the batch size in the cursor option cursor: { batchSize: }.

    You can pass batchSize with AggregationOptions in Spring Mongo 2.x version

    Aggregation aggregation = newAggregation(unwind, group).withOptions(newAggregationOptions().cursorBatchSize(100).build());
    

    With default batch size

    Aggregation aggregation = newAggregation(unwind, group).withOptions(newAggregationOptions().cursor(new Document()).build());
    

提交回复
热议问题