.allowDiskUse(options.isAllowDiskUse());
protected <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, String collectionName, Class<O> outputType, @Nullable AggregationOperationContext context) { Assert.hasText(collectionName, "Collection name must not be null or empty!"); Assert.notNull(aggregation, "Aggregation pipeline must not be null!"); Assert.notNull(outputType, "Output type must not be null!"); Assert.isTrue(!aggregation.getOptions().isExplain(), "Can't use explain option with streaming!"); AggregationUtil aggregationUtil = new AggregationUtil(queryMapper, mappingContext); AggregationOperationContext rootContext = aggregationUtil.prepareAggregationContext(aggregation, context); AggregationOptions options = aggregation.getOptions(); List<Document> pipeline = aggregationUtil.createPipeline(aggregation, rootContext); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Streaming aggregation: {} in collection {}", serializeToJsonSafely(pipeline), collectionName); } ReadDocumentCallback<O> readCallback = new ReadDocumentCallback<>(mongoConverter, outputType, collectionName); return execute(collectionName, (CollectionCallback<CloseableIterator<O>>) collection -> { AggregateIterable<Document> cursor = collection.aggregate(pipeline, Document.class) // .allowDiskUse(options.isAllowDiskUse()) // .useCursor(true); if (options.getCursorBatchSize() != null) { cursor = cursor.batchSize(options.getCursorBatchSize()); } if (options.getCollation().isPresent()) { cursor = cursor.collation(options.getCollation().map(Collation::toMongoCollation).get()); } return new CloseableIterableCursorAdapter<>(cursor, exceptionTranslator, readCallback); }); }
.allowDiskUse(options.isAllowDiskUse());
protected <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, String collectionName, Class<O> outputType, @Nullable AggregationOperationContext context) { Assert.hasText(collectionName, "Collection name must not be null or empty!"); Assert.notNull(aggregation, "Aggregation pipeline must not be null!"); Assert.notNull(outputType, "Output type must not be null!"); Assert.isTrue(!aggregation.getOptions().isExplain(), "Can't use explain option with streaming!"); AggregationUtil aggregationUtil = new AggregationUtil(queryMapper, mappingContext); AggregationOperationContext rootContext = aggregationUtil.prepareAggregationContext(aggregation, context); AggregationOptions options = aggregation.getOptions(); List<Document> pipeline = aggregationUtil.createPipeline(aggregation, rootContext); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Streaming aggregation: {} in collection {}", serializeToJsonSafely(pipeline), collectionName); } ReadDocumentCallback<O> readCallback = new ReadDocumentCallback<>(mongoConverter, outputType, collectionName); return execute(collectionName, (CollectionCallback<CloseableIterator<O>>) collection -> { AggregateIterable<Document> cursor = collection.aggregate(pipeline, Document.class) // .allowDiskUse(options.isAllowDiskUse()) // .useCursor(true); if (options.getCursorBatchSize() != null) { cursor = cursor.batchSize(options.getCursorBatchSize()); } if (options.getCollation().isPresent()) { cursor = cursor.collation(options.getCollation().map(Collation::toMongoCollation).get()); } return new CloseableIterableCursorAdapter<>(cursor, exceptionTranslator, readCallback); }); }
public List<JSONObject> aggregate(String collectionName, List<Bson> query, boolean allowDiskUse) { final List<JSONObject> list = new ArrayList<JSONObject>(); Block<Document> block = new Block<Document>() { public void apply(Document document) { document = iding(document); list.add(parseObject(document.toJson())); } }; getCollection(collectionName).aggregate(query).allowDiskUse(allowDiskUse).forEach(block); return list; }
public <T> List<T> aggregate(String collectionName, List<Bson> query, boolean allowDiskUse, final Class<T> clazz) { final List list = new ArrayList(); Block<Document> block = new Block<Document>() { public void apply(Document document) { document = iding(document); list.add(parseObject(document, clazz)); } }; getCollection(collectionName).aggregate(query).allowDiskUse(allowDiskUse).forEach(block); return list; }
public <T> List<T> aggregate(String collectionName, List<Bson> query, boolean allowDiskUse, final Class<T> clazz) { final List list = new ArrayList(); Block<Document> block = new Block<Document>() { public void apply(Document document) { document = iding(document); list.add(parseObject(document, clazz)); } }; getCollection(collectionName).aggregate(query).allowDiskUse(allowDiskUse).forEach(block); return list; }
public List<JSONObject> aggregate(String collectionName, List<Bson> query, boolean allowDiskUse) { final List<JSONObject> list = new ArrayList<JSONObject>(); Block<Document> block = new Block<Document>() { public void apply(Document document) { document = iding(document); list.add(parseObject(document.toJson())); } }; getCollection(collectionName).aggregate(query).allowDiskUse(allowDiskUse).forEach(block); return list; }
aggregationResult.allowDiskUse(allowDiskUse);
/** * Get the MongoDB cursor. */ private MongoCursor<Document> getCursor(int skip) { if (cursor == null && cursorId == 0) { Document query = Document.parse(config.getMongo().getQuery()); List<Bson> pipes = new ArrayList<>(3); pipes.add(match(query)); pipes.add(skip(skip)); Optional.ofNullable(config.getMongo().getProject()).ifPresent(p -> pipes.add(project(Document.parse(p)))); AggregateIterable<Document> aggregate = collection.aggregate(pipes) .allowDiskUse(true) .useCursor(true); cursor = aggregate.iterator(); // TODO: Persist cursor ID somewhere to allow restarts. Optional.ofNullable(cursor.getServerCursor()).ifPresent(serverCursor -> cursorId = serverCursor.getId()); } else if (cursor == null && cursorId != 0) { // TODO: Lookup cursor ID for resume. // Open existing cursor in case of restart?? } return cursor; } }
.allowDiskUse(true) .batchSize(PIPELINE_BATCH_SIZE) .forEach(new Block<Document>() {
aggregate.allowDiskUse(Boolean.valueOf(System.getProperty(D_AGGREGATION_ALLOW_DISK_USE)));
.getAggregationTimeLimit(), TimeUnit.MILLISECONDS) .allowDiskUse(pipeline .getAllowDiskUse().getValue()); } catch (MongoCommandException