use of com.mongodb.client.model.DBCollectionFindOptions in project mongo-java-driver by mongodb.
the class DBCollection method aggregate.
@SuppressWarnings("deprecation")
private Cursor aggregate(final List<? extends DBObject> pipeline, final AggregationOptions options, final ReadPreference readPreference, final boolean returnCursorForOutCollection) {
if (options == null) {
throw new IllegalArgumentException("options can not be null");
}
List<BsonDocument> stages = preparePipeline(pipeline);
BsonValue outCollection = stages.get(stages.size() - 1).get("$out");
if (outCollection != null) {
AggregateToCollectionOperation operation = new AggregateToCollectionOperation(getNamespace(), stages, getWriteConcern()).maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS).allowDiskUse(options.getAllowDiskUse()).bypassDocumentValidation(options.getBypassDocumentValidation()).collation(options.getCollation());
try {
executor.execute(operation);
if (returnCursorForOutCollection) {
return new DBCursor(database.getCollection(outCollection.asString().getValue()), new BasicDBObject(), new DBCollectionFindOptions().readPreference(primary()).collation(options.getCollation()));
} else {
return null;
}
} catch (MongoWriteConcernException e) {
throw createWriteConcernException(e);
}
} else {
AggregateOperation<DBObject> operation = new AggregateOperation<DBObject>(getNamespace(), stages, getDefaultDBObjectCodec()).readConcern(getReadConcern()).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);
return new MongoCursorAdapter(new MongoBatchCursorAdapter<DBObject>(cursor));
}
}
use of com.mongodb.client.model.DBCollectionFindOptions in project mongo-java-driver by mongodb.
the class DBCollection method aggregate.
/**
* Method implements aggregation framework.
*
* @param pipeline operations to be performed in the aggregation pipeline
* @param options options to apply to the aggregation
* @param readPreference {@link ReadPreference} to be used for this operation
* @return the aggregation operation's result set
* @mongodb.driver.manual core/aggregation-pipeline/ Aggregation
* @mongodb.server.release 2.2
*/
public Cursor aggregate(final List<? extends DBObject> pipeline, final AggregationOptions options, final ReadPreference readPreference) {
Cursor result;
notNull("options", options);
List<BsonDocument> stages = preparePipeline(pipeline);
BsonValue outCollection = stages.get(stages.size() - 1).get("$out");
if (outCollection != null) {
AggregateToCollectionOperation operation = new AggregateToCollectionOperation(getNamespace(), stages, getReadConcern(), getWriteConcern()).maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS).allowDiskUse(options.getAllowDiskUse()).bypassDocumentValidation(options.getBypassDocumentValidation()).collation(options.getCollation());
try {
executor.execute(operation, getReadPreference(), getReadConcern());
result = new DBCursor(database.getCollection(outCollection.asString().getValue()), new BasicDBObject(), new DBCollectionFindOptions().readPreference(primary()).collation(options.getCollation()));
} catch (MongoWriteConcernException e) {
throw createWriteConcernException(e);
}
} else {
AggregateOperation<DBObject> operation = new AggregateOperation<DBObject>(getNamespace(), stages, getDefaultDBObjectCodec()).maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS).allowDiskUse(options.getAllowDiskUse()).batchSize(options.getBatchSize()).collation(options.getCollation()).retryReads(retryReads);
BatchCursor<DBObject> cursor1 = executor.execute(operation, readPreference, getReadConcern());
result = new MongoCursorAdapter(new MongoBatchCursorAdapter<DBObject>(cursor1));
}
return result;
}
use of com.mongodb.client.model.DBCollectionFindOptions in project morphia by mongodb.
the class QueryImpl method compare.
private boolean compare(final FindOptions these, final FindOptions those) {
if (these == null && those != null || these != null && those == null) {
return false;
}
if (these == null) {
return true;
}
DBCollectionFindOptions dbOptions = these.getOptions();
DBCollectionFindOptions that = those.getOptions();
if (dbOptions.getBatchSize() != that.getBatchSize()) {
return false;
}
if (dbOptions.getLimit() != that.getLimit()) {
return false;
}
if (dbOptions.getMaxTime(MILLISECONDS) != that.getMaxTime(MILLISECONDS)) {
return false;
}
if (dbOptions.getMaxAwaitTime(MILLISECONDS) != that.getMaxAwaitTime(MILLISECONDS)) {
return false;
}
if (dbOptions.getSkip() != that.getSkip()) {
return false;
}
if (dbOptions.isNoCursorTimeout() != that.isNoCursorTimeout()) {
return false;
}
if (dbOptions.isOplogReplay() != that.isOplogReplay()) {
return false;
}
if (dbOptions.isPartial() != that.isPartial()) {
return false;
}
if (dbOptions.getModifiers() != null ? !dbOptions.getModifiers().equals(that.getModifiers()) : that.getModifiers() != null) {
return false;
}
if (dbOptions.getProjection() != null ? !dbOptions.getProjection().equals(that.getProjection()) : that.getProjection() != null) {
return false;
}
if (dbOptions.getSort() != null ? !dbOptions.getSort().equals(that.getSort()) : that.getSort() != null) {
return false;
}
if (dbOptions.getCursorType() != that.getCursorType()) {
return false;
}
if (dbOptions.getReadPreference() != null ? !dbOptions.getReadPreference().equals(that.getReadPreference()) : that.getReadPreference() != null) {
return false;
}
if (dbOptions.getReadConcern() != null ? !dbOptions.getReadConcern().equals(that.getReadConcern()) : that.getReadConcern() != null) {
return false;
}
return dbOptions.getCollation() != null ? dbOptions.getCollation().equals(that.getCollation()) : that.getCollation() == null;
}
use of com.mongodb.client.model.DBCollectionFindOptions in project morphia by mongodb.
the class FindOptionsTest method passThrough.
@Test
public void passThrough() {
Collation collation = Collation.builder().locale("en").caseLevel(true).build();
DBCollectionFindOptions options = new FindOptions().batchSize(42).limit(18).modifier("i'm a", "modifier").modifier("i am", 2).projection(new BasicDBObject("field", "value")).maxTime(15, TimeUnit.MINUTES).maxAwaitTime(45, TimeUnit.SECONDS).skip(12).sort(new BasicDBObject("field", -1)).cursorType(CursorType.TailableAwait).noCursorTimeout(true).oplogReplay(true).partial(true).readPreference(ReadPreference.secondaryPreferred(2, TimeUnit.MINUTES)).readConcern(ReadConcern.LOCAL).collation(collation).getOptions();
assertEquals(42, options.getBatchSize());
assertEquals(18, options.getLimit());
assertEquals(new BasicDBObject("i'm a", "modifier").append("i am", 2), options.getModifiers());
assertEquals(new BasicDBObject("field", "value"), options.getProjection());
assertEquals(15, options.getMaxTime(TimeUnit.MINUTES));
assertEquals(45, options.getMaxAwaitTime(TimeUnit.SECONDS));
assertEquals(12, options.getSkip());
assertEquals(new BasicDBObject("field", -1), options.getSort());
assertEquals(CursorType.TailableAwait, options.getCursorType());
assertTrue(options.isNoCursorTimeout());
assertTrue(options.isOplogReplay());
assertTrue(options.isPartial());
assertEquals(ReadPreference.secondaryPreferred(2, TimeUnit.MINUTES), options.getReadPreference());
assertEquals(ReadConcern.LOCAL, options.getReadConcern());
assertEquals(collation, options.getCollation());
}
Aggregations