Search in sources :

Example 96 with BsonString

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

the class AggregateOperation 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 (!isInline(description)) {
        BsonDocument cursor = new BsonDocument();
        if (batchSize != null) {
            cursor.put("batchSize", new BsonInt32(batchSize));
        }
        commandDocument.put("cursor", cursor);
    }
    if (allowDiskUse != null) {
        commandDocument.put("allowDiskUse", BsonBoolean.valueOf(allowDiskUse));
    }
    if (!readConcern.isServerDefault()) {
        commandDocument.put("readConcern", readConcern.asDocument());
    }
    if (collation != null) {
        commandDocument.put("collation", collation.asDocument());
    }
    return commandDocument;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray)

Example 97 with BsonString

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

the class AsyncQueryBatchCursor method asGetMoreCommandDocument.

private BsonDocument asGetMoreCommandDocument(final long cursorId) {
    BsonDocument document = new BsonDocument("getMore", new BsonInt64(cursorId)).append("collection", new BsonString(namespace.getCollectionName()));
    int batchSizeForGetMoreCommand = Math.abs(getNumberToReturn(limit, this.batchSize, count));
    if (batchSizeForGetMoreCommand != 0) {
        document.append("batchSize", new BsonInt32(batchSizeForGetMoreCommand));
    }
    if (maxTimeMS != 0) {
        document.append("maxTimeMS", new BsonInt64(maxTimeMS));
    }
    return document;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Example 98 with BsonString

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

the class BaseWriteOperation method manufactureGetLastErrorResponse.

private BsonDocument manufactureGetLastErrorResponse(final MongoBulkWriteException e) {
    BsonDocument response = new BsonDocument();
    addBulkWriteResultToResponse(e.getWriteResult(), response);
    if (e.getWriteConcernError() != null) {
        response.putAll(e.getWriteConcernError().getDetails());
    }
    if (getLastError(e) != null) {
        response.put("err", new BsonString(getLastError(e).getMessage()));
        response.put("code", new BsonInt32(getLastError(e).getCode()));
        response.putAll(getLastError(e).getDetails());
    } else if (e.getWriteConcernError() != null) {
        response.put("err", new BsonString(e.getWriteConcernError().getMessage()));
        response.put("code", new BsonInt32(e.getWriteConcernError().getCode()));
    }
    return response;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Example 99 with BsonString

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

the class CountOperation method getCommand.

private BsonDocument getCommand() {
    BsonDocument document = new BsonDocument("count", new BsonString(namespace.getCollectionName()));
    putIfNotNull(document, "query", filter);
    putIfNotZero(document, "limit", limit);
    putIfNotZero(document, "skip", skip);
    putIfNotNull(document, "hint", hint);
    putIfNotZero(document, "maxTimeMS", maxTimeMS);
    if (!readConcern.isServerDefault()) {
        document.put("readConcern", readConcern.asDocument());
    }
    if (collation != null) {
        document.put("collation", collation.asDocument());
    }
    return document;
}
Also used : BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Example 100 with BsonString

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

the class CreateCollectionOperation method getCommand.

private BsonDocument getCommand(final ConnectionDescription description) {
    BsonDocument document = new BsonDocument("create", new BsonString(collectionName));
    document.put("autoIndexId", BsonBoolean.valueOf(autoIndex));
    document.put("capped", BsonBoolean.valueOf(capped));
    if (capped) {
        putIfNotZero(document, "size", sizeInBytes);
        putIfNotZero(document, "max", maxDocuments);
    }
    if (usePowerOf2Sizes != null) {
        document.put("flags", new BsonInt32(1));
    }
    if (storageEngineOptions != null) {
        document.put("storageEngine", storageEngineOptions);
    }
    if (indexOptionDefaults != null) {
        document.put("indexOptionDefaults", indexOptionDefaults);
    }
    if (validator != null) {
        document.put("validator", validator);
    }
    if (validationLevel != null) {
        document.put("validationLevel", new BsonString(validationLevel.getValue()));
    }
    if (validationAction != null) {
        document.put("validationAction", new BsonString(validationAction.getValue()));
    }
    appendWriteConcernToCommand(writeConcern, document, description);
    if (collation != null) {
        document.put("collation", collation.asDocument());
    }
    return document;
}
Also used : BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString)

Aggregations

BsonString (org.bson.BsonString)178 BsonDocument (org.bson.BsonDocument)153 BsonInt32 (org.bson.BsonInt32)55 BsonArray (org.bson.BsonArray)48 Test (org.junit.Test)36 Document (org.bson.Document)32 BsonValue (org.bson.BsonValue)31 BsonInt64 (org.bson.BsonInt64)28 ArrayList (java.util.ArrayList)23 Test (org.junit.jupiter.api.Test)18 Map (java.util.Map)14 BsonDouble (org.bson.BsonDouble)14 MongoClientSettings (com.mongodb.MongoClientSettings)13 BsonBinary (org.bson.BsonBinary)13 EncryptOptions (com.mongodb.client.model.vault.EncryptOptions)12 HashMap (java.util.HashMap)12 MongoNamespace (com.mongodb.MongoNamespace)11 List (java.util.List)10 Before (org.junit.Before)10 DataKeyOptions (com.mongodb.client.model.vault.DataKeyOptions)9