use of org.bson.BsonValue in project mongo-java-driver by mongodb.
the class MongoCollectionImpl method toUpdateResult.
private UpdateResult toUpdateResult(final com.mongodb.bulk.BulkWriteResult result) {
if (result.wasAcknowledged()) {
Long modifiedCount = result.isModifiedCountAvailable() ? (long) result.getModifiedCount() : null;
BsonValue upsertedId = result.getUpserts().isEmpty() ? null : result.getUpserts().get(0).getId();
return UpdateResult.acknowledged(result.getMatchedCount(), modifiedCount, upsertedId);
} else {
return UpdateResult.unacknowledged();
}
}
use of org.bson.BsonValue in project mongo-java-driver by mongodb.
the class AggregateIterableImpl method execute.
@SuppressWarnings("deprecation")
private MongoIterable<TResult> execute() {
List<BsonDocument> aggregateList = createBsonDocumentList();
BsonValue outCollection = getAggregateOutCollection(aggregateList);
if (outCollection != null) {
AggregateToCollectionOperation operation = new AggregateToCollectionOperation(namespace, aggregateList, writeConcern).maxTime(maxTimeMS, MILLISECONDS).allowDiskUse(allowDiskUse).bypassDocumentValidation(bypassDocumentValidation).collation(collation);
MongoIterable<TResult> delegated = new FindIterableImpl<TDocument, TResult>(new MongoNamespace(namespace.getDatabaseName(), outCollection.asString().getValue()), documentClass, resultClass, codecRegistry, primary(), readConcern, executor, new BsonDocument(), new FindOptions().collation(collation));
if (batchSize != null) {
delegated.batchSize(batchSize);
}
return new AwaitingWriteOperationIterable<TResult, Void>(operation, executor, delegated);
} else {
return new OperationIterable<TResult>(new AggregateOperation<TResult>(namespace, aggregateList, codecRegistry.get(resultClass)).maxTime(maxTimeMS, MILLISECONDS).allowDiskUse(allowDiskUse).batchSize(batchSize).useCursor(useCursor).readConcern(readConcern).collation(collation), readPreference, executor);
}
}
use of org.bson.BsonValue in project mongo-java-driver by mongodb.
the class AggregateIterableImpl method toCollection.
@Override
public void toCollection(final SingleResultCallback<Void> callback) {
List<BsonDocument> aggregateList = createBsonDocumentList();
BsonValue outCollection = getAggregateOutCollection(aggregateList);
if (outCollection == null) {
throw new IllegalStateException("The last stage of the aggregation pipeline must be $out");
}
executor.execute(new AggregateToCollectionOperation(namespace, aggregateList, writeConcern).maxTime(maxTimeMS, MILLISECONDS).allowDiskUse(allowDiskUse).collation(collation), callback);
}
use of org.bson.BsonValue in project mongo-java-driver by mongodb.
the class MongoCollectionImpl method toUpdateResult.
private UpdateResult toUpdateResult(final com.mongodb.bulk.BulkWriteResult result) {
if (result.wasAcknowledged()) {
Long modifiedCount = result.isModifiedCountAvailable() ? (long) result.getModifiedCount() : null;
BsonValue upsertedId = result.getUpserts().isEmpty() ? null : result.getUpserts().get(0).getId();
return UpdateResult.acknowledged(result.getMatchedCount(), modifiedCount, upsertedId);
} else {
return UpdateResult.unacknowledged();
}
}
use of org.bson.BsonValue in project mongo-java-driver by mongodb.
the class CollectionAcceptanceTest method shouldBeAbleToUseBsonValueToDistinctDocumentsOfVaryingTypes.
@SuppressWarnings("unchecked")
@Test
public void shouldBeAbleToUseBsonValueToDistinctDocumentsOfVaryingTypes() {
List<Object> mixedList = new ArrayList<Object>();
mixedList.add(2);
mixedList.add("d");
mixedList.add(new Document("e", 3));
collection.drop();
collection.insertMany(asList(new Document("id", "a"), new Document("id", 1), new Document("id", new Document("b", "c")), new Document("id", new Document("list", mixedList))));
List<BsonValue> distinct = collection.distinct("id", BsonValue.class).into(new ArrayList<BsonValue>());
assertTrue(distinct.containsAll(asList(new BsonString("a"), new BsonInt32(1), new BsonDocument("b", new BsonString("c")), new BsonDocument("list", new BsonArray(asList(new BsonInt32(2), new BsonString("d"), new BsonDocument("e", new BsonInt32(3))))))));
distinct = collection.distinct("id", new Document("id", new Document("$ne", 1)), BsonValue.class).into(new ArrayList<BsonValue>());
assertTrue(distinct.containsAll(asList(new BsonString("a"), new BsonDocument("b", new BsonString("c")), new BsonDocument("list", new BsonArray(asList(new BsonInt32(2), new BsonString("d"), new BsonDocument("e", new BsonInt32(3))))))));
}
Aggregations