use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class MongoDatabaseImpl method createBsonDocumentList.
private List<BsonDocument> createBsonDocumentList(final List<? extends Bson> pipeline) {
notNull("pipeline", pipeline);
List<BsonDocument> bsonDocumentPipeline = new ArrayList<BsonDocument>(pipeline.size());
for (Bson obj : pipeline) {
if (obj == null) {
throw new IllegalArgumentException("pipeline can not contain a null value");
}
bsonDocumentPipeline.add(obj.toBsonDocument(BsonDocument.class, codecRegistry));
}
return bsonDocumentPipeline;
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class MongoDatabaseImpl method createCollection.
@Override
@SuppressWarnings("deprecation")
public void createCollection(final String collectionName, final CreateCollectionOptions createCollectionOptions, final SingleResultCallback<Void> callback) {
CreateCollectionOperation operation = new CreateCollectionOperation(name, collectionName, writeConcern).capped(createCollectionOptions.isCapped()).sizeInBytes(createCollectionOptions.getSizeInBytes()).autoIndex(createCollectionOptions.isAutoIndex()).maxDocuments(createCollectionOptions.getMaxDocuments()).usePowerOf2Sizes(createCollectionOptions.isUsePowerOf2Sizes()).storageEngineOptions(toBsonDocument(createCollectionOptions.getStorageEngineOptions())).collation(createCollectionOptions.getCollation());
IndexOptionDefaults indexOptionDefaults = createCollectionOptions.getIndexOptionDefaults();
if (indexOptionDefaults.getStorageEngine() != null) {
operation.indexOptionDefaults(new BsonDocument("storageEngine", toBsonDocument(indexOptionDefaults.getStorageEngine())));
}
ValidationOptions validationOptions = createCollectionOptions.getValidationOptions();
if (validationOptions.getValidator() != null) {
operation.validator(toBsonDocument(validationOptions.getValidator()));
}
if (validationOptions.getValidationLevel() != null) {
operation.validationLevel(validationOptions.getValidationLevel());
}
if (validationOptions.getValidationAction() != null) {
operation.validationAction(validationOptions.getValidationAction());
}
executor.execute(operation, callback);
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class GridFSBucketImpl method rename.
@Override
public void rename(final BsonValue id, final String newFilename, final SingleResultCallback<Void> callback) {
notNull("id", id);
notNull("newFilename", newFilename);
notNull("callback", callback);
final SingleResultCallback<Void> errHandlingCallback = errorHandlingCallback(callback, LOGGER);
filesCollection.updateOne(new BsonDocument("_id", id), new BsonDocument("$set", new BsonDocument("filename", new BsonString(newFilename))), new SingleResultCallback<UpdateResult>() {
@Override
public void onResult(final UpdateResult result, final Throwable t) {
if (t != null) {
errHandlingCallback.onResult(null, t);
} else if (result.wasAcknowledged() && result.getMatchedCount() == 0) {
errHandlingCallback.onResult(null, new MongoGridFSException(format("No file found with the ObjectId: %s", id)));
} else {
errHandlingCallback.onResult(null, null);
}
}
});
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class ClientMetadataHelper method addDriverInformation.
private static BsonDocument addDriverInformation(final MongoDriverInformation mongoDriverInformation, final BsonDocument document) {
MongoDriverInformation driverInformation = getDriverInformation(mongoDriverInformation);
BsonDocument driverMetadataDocument = new BsonDocument(DRIVER_NAME_FIELD, listToBsonString(driverInformation.getDriverNames())).append(DRIVER_VERSION_FIELD, listToBsonString(driverInformation.getDriverVersions()));
document.append(DRIVER_FIELD, driverMetadataDocument);
document.append(PLATFORM_FIELD, listToBsonString(driverInformation.getDriverPlatforms()));
return document;
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class CommandProtocol method sendSucceededEvent.
private void sendSucceededEvent(final ConnectionDescription connectionDescription, final long startTimeNanos, final CommandMessage commandMessage, final BsonDocument response) {
if (commandListener != null) {
BsonDocument responseDocumentForEvent = (SECURITY_SENSITIVE_COMMANDS.contains(getCommandName())) ? new BsonDocument() : response;
sendCommandSucceededEvent(commandMessage, getCommandName(), responseDocumentForEvent, connectionDescription, startTimeNanos, commandListener);
}
}
Aggregations