Java Driver allowDiskUse:true

Java Driver Version: org.mongodb:mongodb-driver-sync:4.0.5

I am trying to figure out how to pass in allowDiskUse: true to my aggregation pipeline. I have done some searching and found that the following should work

import com.mongodb.AggregationOptions;
AggregationOptions options = AggregationOptions.builder().allowDiskUse(true).build();
List<Document> queryResults = collection.aggregate(this.pipeline).withOptions(options).into(new ArrayList<>());

However I get the following error

error: cannot find symbol
import com.mongodb.AggregationOptions;
  symbol:   class AggregationOptions
  location: package com.mongodb

This link to leads me to believe that this package should contain this class. I am using the com.mongodb package in several other locations without issue.

What is the best way to specify allowDiskUse:true in mongodb’s Java Driver? Any ideas why that package import isn’t working?

Thanks so much!

The solution was this

List<Document> queryResults = collection.aggregate(this.pipeline).allowDiskUse(true).into(new ArrayList<>());
1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.