Spring Data-MongoDb Options for aggregation method

北慕城南 提交于 2019-12-20 03:29:44

问题


How can i set "allowDiskUse" option in aggregation method in spring data-mongodb framework ?


回答1:


The core aggregation abstraction in Spring Data MongoDB is - as the name suggests - Aggregation. It exposes a fluent API to build up a pipeline using aggregation operations.

As of version 1.6.0.M1 the Aggregation class has a ….withOptions(…) method to be used like this:

Aggregation aggregation = newAggregation(…) // build up pipeline in here
  .withOptions(newAggregationOptions().allowDiskUse(true).build());



回答2:


I found spring data-mongodb to have limited support for the aggregation framework, however you can simply use the native library leveraging spring mongo template:

mongoTemplate.getCollection("myCollection").aggregate(pipeline)

See https://github.com/mongodb/mongo-java-driver/blob/master/src/test/com/mongodb/AggregationTest.java on how to setup the List<DBObject> pipeline and how to setup allowDiskUse to true using the AggregationOptions.



来源:https://stackoverflow.com/questions/25224088/spring-data-mongodb-options-for-aggregation-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!