Search in sources :

Example 1 with BsonDocument

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;
}
Also used : BsonDocument(org.bson.BsonDocument) ArrayList(java.util.ArrayList) Bson(org.bson.conversions.Bson)

Example 2 with BsonDocument

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);
}
Also used : CreateCollectionOperation(com.mongodb.operation.CreateCollectionOperation) BsonDocument(org.bson.BsonDocument) ValidationOptions(com.mongodb.client.model.ValidationOptions) IndexOptionDefaults(com.mongodb.client.model.IndexOptionDefaults)

Example 3 with BsonDocument

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);
            }
        }
    });
}
Also used : BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) MongoGridFSException(com.mongodb.MongoGridFSException) UpdateResult(com.mongodb.client.result.UpdateResult)

Example 4 with BsonDocument

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;
}
Also used : BsonDocument(org.bson.BsonDocument) MongoDriverInformation(com.mongodb.client.MongoDriverInformation)

Example 5 with BsonDocument

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);
    }
}
Also used : BsonDocument(org.bson.BsonDocument)

Aggregations

BsonDocument (org.bson.BsonDocument)565 BsonString (org.bson.BsonString)218 Test (org.junit.Test)127 BsonValue (org.bson.BsonValue)124 BsonInt32 (org.bson.BsonInt32)97 BsonArray (org.bson.BsonArray)89 ArrayList (java.util.ArrayList)75 Document (org.bson.Document)63 Map (java.util.Map)49 Test (org.junit.jupiter.api.Test)46 BsonDocumentReader (org.bson.BsonDocumentReader)43 BsonInt64 (org.bson.BsonInt64)39 MongoNamespace (com.mongodb.MongoNamespace)37 BsonDocumentWriter (org.bson.BsonDocumentWriter)36 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)35 BsonBinary (org.bson.BsonBinary)33 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)29 List (java.util.List)28 Before (org.junit.Before)27 HashMap (java.util.HashMap)23