Search in sources :

Example 41 with BsonDocument

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

the class AggregateExplainOperation method getCommand.

private BsonDocument getCommand() {
    BsonDocument commandDocument = new BsonDocument("aggregate", new BsonString(namespace.getCollectionName()));
    commandDocument.put("pipeline", new BsonArray(pipeline));
    commandDocument.put("explain", BsonBoolean.TRUE);
    if (maxTimeMS > 0) {
        commandDocument.put("maxTimeMS", new BsonInt64(maxTimeMS));
    }
    if (allowDiskUse != null) {
        commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
    }
    if (collation != null) {
        commandDocument.put("collation", collation.asDocument());
    }
    return commandDocument;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray)

Example 42 with BsonDocument

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

the class AggregateToCollectionOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument commandDocument = new BsonDocument("aggregate", new BsonString(namespace.getCollectionName()));
    commandDocument.put("pipeline", new BsonArray(pipeline));
    if (maxTimeMS > 0) {
        commandDocument.put("maxTimeMS", new BsonInt64(maxTimeMS));
    }
    if (allowDiskUse != null) {
        commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
    }
    if (bypassDocumentValidation != null && serverIsAtLeastVersionThreeDotTwo(description)) {
        commandDocument.put("bypassDocumentValidation", BsonBoolean.valueOf(bypassDocumentValidation));
    }
    if (serverIsAtLeastVersionThreeDotSix(description)) {
        commandDocument.put("cursor", new BsonDocument());
    }
    appendWriteConcernToCommand(writeConcern, commandDocument, description);
    if (collation != null) {
        commandDocument.put("collation", collation.asDocument());
    }
    return commandDocument;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray)

Example 43 with BsonDocument

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

the class CreateIndexesOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument command = new BsonDocument("createIndexes", new BsonString(namespace.getCollectionName()));
    List<BsonDocument> values = new ArrayList<BsonDocument>();
    for (IndexRequest request : requests) {
        values.add(getIndex(request));
    }
    command.put("indexes", new BsonArray(values));
    appendWriteConcernToCommand(writeConcern, command, description);
    return command;
}
Also used : BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) ArrayList(java.util.ArrayList) IndexRequest(com.mongodb.bulk.IndexRequest)

Example 44 with BsonDocument

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

the class CreateUserOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument commandDocument = asCommandDocument(credential, readOnly, "createUser");
    appendWriteConcernToCommand(writeConcern, commandDocument, description);
    return commandDocument;
}
Also used : BsonDocument(org.bson.BsonDocument)

Example 45 with BsonDocument

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

the class DB method getCreateCollectionOperation.

@SuppressWarnings("deprecation")
private CreateCollectionOperation getCreateCollectionOperation(final String collectionName, final DBObject options) {
    if (options.get("size") != null && !(options.get("size") instanceof Number)) {
        throw new IllegalArgumentException("'size' should be Number");
    }
    if (options.get("max") != null && !(options.get("max") instanceof Number)) {
        throw new IllegalArgumentException("'max' should be Number");
    }
    if (options.get("capped") != null && !(options.get("capped") instanceof Boolean)) {
        throw new IllegalArgumentException("'capped' should be Boolean");
    }
    if (options.get("autoIndexId") != null && !(options.get("autoIndexId") instanceof Boolean)) {
        throw new IllegalArgumentException("'autoIndexId' should be Boolean");
    }
    if (options.get("storageEngine") != null && !(options.get("storageEngine") instanceof DBObject)) {
        throw new IllegalArgumentException("'storageEngine' should be DBObject");
    }
    if (options.get("indexOptionDefaults") != null && !(options.get("indexOptionDefaults") instanceof DBObject)) {
        throw new IllegalArgumentException("'indexOptionDefaults' should be DBObject");
    }
    if (options.get("validator") != null && !(options.get("validator") instanceof DBObject)) {
        throw new IllegalArgumentException("'validator' should be DBObject");
    }
    if (options.get("validationLevel") != null && !(options.get("validationLevel") instanceof String)) {
        throw new IllegalArgumentException("'validationLevel' should be String");
    }
    if (options.get("validationAction") != null && !(options.get("validationAction") instanceof String)) {
        throw new IllegalArgumentException("'validationAction' should be String");
    }
    boolean capped = false;
    boolean autoIndex = true;
    long sizeInBytes = 0;
    long maxDocuments = 0;
    Boolean usePowerOfTwoSizes = null;
    BsonDocument storageEngineOptions = null;
    BsonDocument indexOptionDefaults = null;
    BsonDocument validator = null;
    ValidationLevel validationLevel = null;
    ValidationAction validationAction = null;
    if (options.get("capped") != null) {
        capped = (Boolean) options.get("capped");
    }
    if (options.get("size") != null) {
        sizeInBytes = ((Number) options.get("size")).longValue();
    }
    if (options.get("autoIndexId") != null) {
        autoIndex = (Boolean) options.get("autoIndexId");
    }
    if (options.get("max") != null) {
        maxDocuments = ((Number) options.get("max")).longValue();
    }
    if (options.get("usePowerOfTwoSizes") != null) {
        usePowerOfTwoSizes = (Boolean) options.get("usePowerOfTwoSizes");
    }
    if (options.get("storageEngine") != null) {
        storageEngineOptions = wrap((DBObject) options.get("storageEngine"));
    }
    if (options.get("indexOptionDefaults") != null) {
        indexOptionDefaults = wrap((DBObject) options.get("indexOptionDefaults"));
    }
    if (options.get("validator") != null) {
        validator = wrap((DBObject) options.get("validator"));
    }
    if (options.get("validationLevel") != null) {
        validationLevel = ValidationLevel.fromString((String) options.get("validationLevel"));
    }
    if (options.get("validationAction") != null) {
        validationAction = ValidationAction.fromString((String) options.get("validationAction"));
    }
    Collation collation = DBObjectCollationHelper.createCollationFromOptions(options);
    return new CreateCollectionOperation(getName(), collectionName, getWriteConcern()).capped(capped).collation(collation).sizeInBytes(sizeInBytes).autoIndex(autoIndex).maxDocuments(maxDocuments).usePowerOf2Sizes(usePowerOfTwoSizes).storageEngineOptions(storageEngineOptions).indexOptionDefaults(indexOptionDefaults).validator(validator).validationLevel(validationLevel).validationAction(validationAction);
}
Also used : CreateCollectionOperation(com.mongodb.operation.CreateCollectionOperation) BsonDocument(org.bson.BsonDocument) ValidationAction(com.mongodb.client.model.ValidationAction) ValidationLevel(com.mongodb.client.model.ValidationLevel) Collation(com.mongodb.client.model.Collation)

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