Search in sources :

Example 31 with BsonDocument

use of org.bson.BsonDocument in project mongo-java-driver by mongodb.

the class CollectionHelper method create.

public void create(final String collectionName, final CreateCollectionOptions options) {
    drop(namespace);
    CreateCollectionOperation operation = new CreateCollectionOperation(namespace.getDatabaseName(), collectionName, WriteConcern.ACKNOWLEDGED).capped(options.isCapped()).sizeInBytes(options.getSizeInBytes()).autoIndex(options.isAutoIndex()).maxDocuments(options.getMaxDocuments());
    IndexOptionDefaults indexOptionDefaults = options.getIndexOptionDefaults();
    if (indexOptionDefaults.getStorageEngine() != null) {
        operation.indexOptionDefaults(new BsonDocument("storageEngine", toBsonDocument(indexOptionDefaults.getStorageEngine())));
    }
    ValidationOptions validationOptions = options.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());
    }
    operation.execute(getBinding());
}
Also used : CreateCollectionOperation(com.mongodb.operation.CreateCollectionOperation) BsonDocument(org.bson.BsonDocument) ValidationOptions(com.mongodb.client.model.ValidationOptions) IndexOptionDefaults(com.mongodb.client.model.IndexOptionDefaults)

Example 32 with BsonDocument

use of org.bson.BsonDocument in project mongo-java-driver by mongodb.

the class DropDatabaseOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument commandDocument = new BsonDocument("dropDatabase", new BsonInt32(1));
    appendWriteConcernToCommand(writeConcern, commandDocument, description);
    return commandDocument;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument)

Example 33 with BsonDocument

use of org.bson.BsonDocument in project mongo-java-driver by mongodb.

the class DropIndexOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument commandDocument = new BsonDocument("dropIndexes", new BsonString(namespace.getCollectionName())).append("index", new BsonString(indexName));
    appendWriteConcernToCommand(writeConcern, commandDocument, description);
    return commandDocument;
}
Also used : BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Example 34 with BsonDocument

use of org.bson.BsonDocument in project mongo-java-driver by mongodb.

the class FindAndDeleteOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument commandDocument = new BsonDocument("findandmodify", new BsonString(namespace.getCollectionName()));
    putIfNotNull(commandDocument, "query", getFilter());
    putIfNotNull(commandDocument, "fields", getProjection());
    putIfNotNull(commandDocument, "sort", getSort());
    putIfNotZero(commandDocument, "maxTimeMS", getMaxTime(MILLISECONDS));
    commandDocument.put("remove", BsonBoolean.TRUE);
    if (serverIsAtLeastVersionThreeDotTwo(description) && writeConcern.isAcknowledged() && !writeConcern.isServerDefault()) {
        commandDocument.put("writeConcern", writeConcern.asDocument());
    }
    if (collation != null) {
        commandDocument.put("collation", collation.asDocument());
    }
    return commandDocument;
}
Also used : BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Example 35 with BsonDocument

use of org.bson.BsonDocument in project mongo-java-driver by mongodb.

the class UpdateProtocol method getAsWriteCommand.

@Override
protected BsonDocument getAsWriteCommand(final ByteBufferBsonOutput bsonOutput, final int firstDocumentPosition) {
    List<ByteBufBsonDocument> documents = ByteBufBsonDocument.create(bsonOutput, firstDocumentPosition);
    BsonDocument updateDocument = new BsonDocument("q", documents.get(0)).append("u", documents.get(1));
    if (updates.get(0).isMulti()) {
        updateDocument.append("multi", BsonBoolean.TRUE);
    }
    if (updates.get(0).isUpsert()) {
        updateDocument.append("upsert", BsonBoolean.TRUE);
    }
    return getBaseCommandDocument("update").append("updates", new BsonArray(singletonList(updateDocument)));
}
Also used : BsonDocument(org.bson.BsonDocument) BsonArray(org.bson.BsonArray)

Aggregations

BsonDocument (org.bson.BsonDocument)169 BsonString (org.bson.BsonString)53 BsonValue (org.bson.BsonValue)37 Test (org.junit.Test)36 BsonArray (org.bson.BsonArray)29 BsonInt32 (org.bson.BsonInt32)28 ArrayList (java.util.ArrayList)24 BsonDocumentReader (org.bson.BsonDocumentReader)17 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)14 BsonDocumentWriter (org.bson.BsonDocumentWriter)14 BsonInt64 (org.bson.BsonInt64)14 BsonDocumentCodec (org.bson.codecs.BsonDocumentCodec)10 BsonDouble (org.bson.BsonDouble)8 Document (org.bson.Document)7 MongoNamespace (com.mongodb.MongoNamespace)6 Before (org.junit.Before)6 MongoGridFSException (com.mongodb.MongoGridFSException)5 BsonObjectId (org.bson.BsonObjectId)5 BsonWriter (org.bson.BsonWriter)5 ObjectId (org.bson.types.ObjectId)5