Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What replaces MongoDB AggregationOutput class?

Tags:

java

mongodb

All of the methods have being deprecated but I havn't been able to find the replacement class for aggregation with the java driver.

like image 213
user2312688 Avatar asked Feb 13 '23 23:02

user2312688


1 Answers

Thanks to evanchooly answer, here is what to do.
Replace:

 AggregationOutput output = collection.aggregate(pipe);
 for (DBObject obj : output.results()) {
     //...
 }

by

  // this build of options is taken from the original method
  // aggregate(pipe) to have same behaviour
  AggregationOptions options = AggregationOptions.builder()
            .outputMode(AggregationOptions.OutputMode.INLINE)
            .build();

  Cursor cursor = collection.aggregate(pipe,options); 
  while (cursor.hasNext() ) {
      DBObject obj = cursor.next();
      //...
  }
like image 146
JR Utily Avatar answered Feb 15 '23 13:02

JR Utily