@SuppressWarnings("deprecation") <TResult> AggregateOperation<TResult> aggregate(final List<? extends Bson> pipeline, final Class<TResult> resultClass, final long maxTimeMS, final long maxAwaitTimeMS, final Integer batchSize, final Collation collation, final Bson hint, final String comment, final Boolean allowDiskUse, final Boolean useCursor, final AggregationLevel aggregationLevel) { return new AggregateOperation<TResult>(namespace, toBsonDocumentList(pipeline), codecRegistry.get(resultClass), aggregationLevel) .maxTime(maxTimeMS, MILLISECONDS) .maxAwaitTime(maxAwaitTimeMS, MILLISECONDS) .allowDiskUse(allowDiskUse) .batchSize(batchSize) .useCursor(useCursor) .collation(collation) .hint(hint == null ? null : hint.toBsonDocument(documentClass, codecRegistry)) .comment(comment); }
/** * Return the explain plan for the aggregation pipeline. * * @param pipeline the aggregation pipeline to explain * @param options the options to apply to the aggregation * @return the command result. The explain output may change from release to release, so best to simply log this. * @mongodb.driver.manual core/aggregation-pipeline/ Aggregation * @mongodb.driver.manual reference/operator/meta/explain/ Explain query * @mongodb.server.release 2.6 */ public CommandResult explainAggregate(final List<? extends DBObject> pipeline, final AggregationOptions options) { AggregateOperation<BsonDocument> operation = new AggregateOperation<BsonDocument>(getNamespace(), preparePipeline(pipeline), new BsonDocumentCodec()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .allowDiskUse(options.getAllowDiskUse()) .collation(options.getCollation()); return new CommandResult(executor.execute(operation.asExplainableOperation(ExplainVerbosity.QUERY_PLANNER), primaryPreferred(), getReadConcern())); }
@Override public String toString() { return "AggregateOperation{" + "namespace=" + getNamespace() + ", pipeline=" + getPipeline() + ", decoder=" + getDecoder() + ", allowDiskUse=" + getAllowDiskUse() + ", batchSize=" + getBatchSize() + ", collation=" + getCollation() + ", comment=" + getComment() + ", hint=" + getHint() + ", maxAwaitTimeMS=" + getMaxAwaitTime(TimeUnit.MILLISECONDS) + ", maxTimeMS=" + getMaxTime(TimeUnit.MILLISECONDS) + ", useCursor=" + wrapped.getUseCursor() + "}"; } }
private AggregateOperation<BsonDocument> getAggregateOperation() { return new AggregateOperation<BsonDocument>(namespace, getPipeline(), DECODER) .collation(collation) .hint(hint) .maxTime(maxTimeMS, TimeUnit.MILLISECONDS); }
AggregateOperation<DBObject> operation = new AggregateOperation<DBObject>(getNamespace(), stages, getDefaultDBObjectCodec()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .allowDiskUse(options.getAllowDiskUse()) .batchSize(options.getBatchSize()) .useCursor(options.getOutputMode() == com.mongodb.AggregationOptions.OutputMode.CURSOR) .collation(options.getCollation()); BatchCursor<DBObject> cursor = executor.execute(operation, readPreference, getReadConcern()); return new MongoCursorAdapter(new MongoBatchCursorAdapter<DBObject>(cursor));
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public AsyncReadOperation<BsonDocument> asExplainableOperationAsync(final ExplainVerbosity explainVerbosity) { return new AggregateExplainOperation(getNamespace(), getPipeline()) .allowDiskUse(getAllowDiskUse()) .maxTime(getMaxAwaitTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) .hint(wrapped.getHint()); }
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public ReadOperation<BsonDocument> asExplainableOperation(final ExplainVerbosity explainVerbosity) { if (countStrategy.equals(CountStrategy.COMMAND)) { return createExplainableOperation(explainVerbosity); } else { return getAggregateOperation().asExplainableOperation(explainVerbosity); } }
/** {@inheritDoc} */ @Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { Object operation = args[0]; final String operationName; if (operation instanceof AggregateOperation<?>) { operationName = Joiner.on(",").join(((AggregateOperation<?>) operation).getPipeline()); } else if (operation instanceof ListIndexesOperation<?>) { operationName = "indexes"; } else if (operation instanceof FindOperation<?>) { FindOperation<?> findOperation = (FindOperation<?>) operation; operationName = "find(" + findOperation.getFilter().toJson() + ")"; } else if (operation instanceof CountOperation) { operationName = "count(" + ((CountOperation) operation).getFilter().toJson() + ")"; } else if (operation instanceof UpdateOperation) { UpdateOperation updateOperation = (UpdateOperation) operation; List<UpdateRequest> updateRequests = updateOperation.getUpdateRequests(); operationName = updateRequests.stream().map(ur -> "{" + ur.getType() + ur.getFilter() + "}").collect(Collectors.joining(",")); } else { operationName = operation.toString(); } return doInvoke(operationExecutor, method, args, operationName); } }
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public AsyncReadOperation<BsonDocument> asExplainableOperationAsync(final ExplainVerbosity explainVerbosity) { if (countStrategy.equals(CountStrategy.COMMAND)) { return createExplainableOperation(explainVerbosity); } else { return getAggregateOperation().asExplainableOperationAsync(explainVerbosity); } }
AggregateOperation<DBObject> operation = new AggregateOperation<DBObject>(getNamespace(), stages, getDefaultDBObjectCodec()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .allowDiskUse(options.getAllowDiskUse()) .batchSize(options.getBatchSize()) .useCursor(options.getOutputMode() == com.mongodb.AggregationOptions.OutputMode.CURSOR) .collation(options.getCollation()); BatchCursor<DBObject> cursor = executor.execute(operation, readPreference, getReadConcern()); return new MongoCursorAdapter(new MongoBatchCursorAdapter<DBObject>(cursor));
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public ReadOperation<BsonDocument> asExplainableOperation(final ExplainVerbosity explainVerbosity) { return new AggregateExplainOperation(getNamespace(), getPipeline()) .allowDiskUse(getAllowDiskUse()) .maxTime(getMaxAwaitTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) .hint(wrapped.getHint()); }
private AggregateOperation<BsonDocument> getAggregateOperation() { return new AggregateOperation<BsonDocument>(namespace, getPipeline(), DECODER) .collation(collation) .hint(hint) .maxTime(maxTimeMS, TimeUnit.MILLISECONDS); }
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public ReadOperation<BsonDocument> asExplainableOperation(final ExplainVerbosity explainVerbosity) { if (countStrategy.equals(CountStrategy.COMMAND)) { return createExplainableOperation(explainVerbosity); } else { return getAggregateOperation().asExplainableOperation(explainVerbosity); } }
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public AsyncReadOperation<BsonDocument> asExplainableOperationAsync(final ExplainVerbosity explainVerbosity) { if (countStrategy.equals(CountStrategy.COMMAND)) { return createExplainableOperation(explainVerbosity); } else { return getAggregateOperation().asExplainableOperationAsync(explainVerbosity); } }
@SuppressWarnings("deprecation") <TResult> AggregateOperation<TResult> aggregate(final List<? extends Bson> pipeline, final Class<TResult> resultClass, final long maxTimeMS, final long maxAwaitTimeMS, final Integer batchSize, final Collation collation, final Bson hint, final String comment, final Boolean allowDiskUse, final Boolean useCursor, final AggregationLevel aggregationLevel) { return new AggregateOperation<TResult>(namespace, toBsonDocumentList(pipeline), codecRegistry.get(resultClass), aggregationLevel) .maxTime(maxTimeMS, MILLISECONDS) .maxAwaitTime(maxAwaitTimeMS, MILLISECONDS) .allowDiskUse(allowDiskUse) .batchSize(batchSize) .useCursor(useCursor) .collation(collation) .hint(hint == null ? null : hint.toBsonDocument(documentClass, codecRegistry)) .comment(comment); }
@Override public String toString() { return "AggregateOperation{" + "namespace=" + getNamespace() + ", pipeline=" + getPipeline() + ", decoder=" + getDecoder() + ", allowDiskUse=" + getAllowDiskUse() + ", batchSize=" + getBatchSize() + ", collation=" + getCollation() + ", comment=" + getComment() + ", hint=" + getHint() + ", maxAwaitTimeMS=" + getMaxAwaitTime(TimeUnit.MILLISECONDS) + ", maxTimeMS=" + getMaxTime(TimeUnit.MILLISECONDS) + ", useCursor=" + wrapped.getUseCursor() + "}"; } }
/** * Return the explain plan for the aggregation pipeline. * * @param pipeline the aggregation pipeline to explain * @param options the options to apply to the aggregation * @return the command result. The explain output may change from release to release, so best to simply log this. * @mongodb.driver.manual core/aggregation-pipeline/ Aggregation * @mongodb.driver.manual reference/operator/meta/explain/ Explain query * @mongodb.server.release 2.6 */ public CommandResult explainAggregate(final List<? extends DBObject> pipeline, final AggregationOptions options) { AggregateOperation<BsonDocument> operation = new AggregateOperation<BsonDocument>(getNamespace(), preparePipeline(pipeline), new BsonDocumentCodec()) .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS) .allowDiskUse(options.getAllowDiskUse()) .collation(options.getCollation()); return new CommandResult(executor.execute(operation.asExplainableOperation(ExplainVerbosity.QUERY_PLANNER), primaryPreferred(), getReadConcern())); }
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public AsyncReadOperation<BsonDocument> asExplainableOperationAsync(final ExplainVerbosity explainVerbosity) { return new AggregateExplainOperation(getNamespace(), getPipeline()) .allowDiskUse(getAllowDiskUse()) .maxTime(getMaxAwaitTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) .hint(wrapped.getHint()); }
/** * Gets an operation whose execution explains this operation. * * @param explainVerbosity the explain verbosity * @return a read operation that when executed will explain this operation */ public ReadOperation<BsonDocument> asExplainableOperation(final ExplainVerbosity explainVerbosity) { return new AggregateExplainOperation(getNamespace(), getPipeline()) .allowDiskUse(getAllowDiskUse()) .maxTime(getMaxAwaitTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS) .hint(wrapped.getHint()); }