2

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

2 Answers 2

5

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());
Sign up to request clarification or add additional context in comments.

4 Comments

Thanx Oliver,well what about version 1.3.2 ? and what about in version 1.5.2 ?
They don't have that feature, that's why I explicitly named 1.6 M1.
I did the same but still getting the same error. do i need to configure something else? Using mongo version 3.4
Solutions works! Previously i was doing aggregation.withOptions( options ) separately and it ignored my custom configuration;
-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.

1 Comment

I was not being negative, I didn't know in version 1.6.0 (which is not in GA) there was a support for that nor there is anything in the documentation. I am glad more support is coming for the Aggregation framework. I do use Spring MongoDB quite a lot and in general I am very happy with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.