Search in sources :

Example 26 with BsonInt64

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

the class QueryProtocol method asFindCommandResponseDocument.

private BsonDocument asFindCommandResponseDocument(final ResponseBuffers responseBuffers, final QueryResult<T> queryResult, final boolean isExplain) {
    List<ByteBufBsonDocument> rawResultDocuments = Collections.emptyList();
    if (responseBuffers.getReplyHeader().getNumberReturned() > 0) {
        responseBuffers.getBodyByteBuffer().position(0);
        rawResultDocuments = ByteBufBsonDocument.create(responseBuffers);
    }
    if (isExplain) {
        BsonDocument explainCommandResponseDocument = new BsonDocument("ok", new BsonDouble(1));
        explainCommandResponseDocument.putAll(rawResultDocuments.get(0));
        return explainCommandResponseDocument;
    } else {
        BsonDocument cursorDocument = new BsonDocument("id", queryResult.getCursor() == null ? new BsonInt64(0) : new BsonInt64(queryResult.getCursor().getId())).append("ns", new BsonString(namespace.getFullName())).append("firstBatch", new BsonArray(rawResultDocuments));
        return new BsonDocument("cursor", cursorDocument).append("ok", new BsonDouble(1));
    }
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) BsonDouble(org.bson.BsonDouble)

Example 27 with BsonInt64

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

the class OperationHelper method cursorDocumentToQueryResult.

private static <T> QueryResult<T> cursorDocumentToQueryResult(final BsonDocument cursorDocument, final ServerAddress serverAddress, final String fieldNameContainingBatch) {
    long cursorId = ((BsonInt64) cursorDocument.get("id")).getValue();
    MongoNamespace queryResultNamespace = new MongoNamespace(cursorDocument.getString("ns").getValue());
    return new QueryResult<T>(queryResultNamespace, BsonDocumentWrapperHelper.<T>toList(cursorDocument, fieldNameContainingBatch), cursorId, serverAddress);
}
Also used : BsonInt64(org.bson.BsonInt64) QueryResult(com.mongodb.connection.QueryResult) MongoNamespace(com.mongodb.MongoNamespace)

Example 28 with BsonInt64

use of org.bson.BsonInt64 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 29 with BsonInt64

use of org.bson.BsonInt64 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 30 with BsonInt64

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

the class CreateIndexesOperation method getIndex.

private BsonDocument getIndex(final IndexRequest request) {
    BsonDocument index = new BsonDocument();
    index.append("key", request.getKeys());
    index.append("name", new BsonString(request.getName() != null ? request.getName() : generateIndexName(request.getKeys())));
    index.append("ns", new BsonString(namespace.getFullName()));
    if (request.isBackground()) {
        index.append("background", BsonBoolean.TRUE);
    }
    if (request.isUnique()) {
        index.append("unique", BsonBoolean.TRUE);
    }
    if (request.isSparse()) {
        index.append("sparse", BsonBoolean.TRUE);
    }
    if (request.getExpireAfter(TimeUnit.SECONDS) != null) {
        index.append("expireAfterSeconds", new BsonInt64(request.getExpireAfter(TimeUnit.SECONDS)));
    }
    if (request.getVersion() != null) {
        index.append("v", new BsonInt32(request.getVersion()));
    }
    if (request.getWeights() != null) {
        index.append("weights", request.getWeights());
    }
    if (request.getDefaultLanguage() != null) {
        index.append("default_language", new BsonString(request.getDefaultLanguage()));
    }
    if (request.getLanguageOverride() != null) {
        index.append("language_override", new BsonString(request.getLanguageOverride()));
    }
    if (request.getTextVersion() != null) {
        index.append("textIndexVersion", new BsonInt32(request.getTextVersion()));
    }
    if (request.getSphereVersion() != null) {
        index.append("2dsphereIndexVersion", new BsonInt32(request.getSphereVersion()));
    }
    if (request.getBits() != null) {
        index.append("bits", new BsonInt32(request.getBits()));
    }
    if (request.getMin() != null) {
        index.append("min", new BsonDouble(request.getMin()));
    }
    if (request.getMax() != null) {
        index.append("max", new BsonDouble(request.getMax()));
    }
    if (request.getBucketSize() != null) {
        index.append("bucketSize", new BsonDouble(request.getBucketSize()));
    }
    if (request.getDropDups()) {
        index.append("dropDups", BsonBoolean.TRUE);
    }
    if (request.getStorageEngine() != null) {
        index.append("storageEngine", request.getStorageEngine());
    }
    if (request.getPartialFilterExpression() != null) {
        index.append("partialFilterExpression", request.getPartialFilterExpression());
    }
    if (request.getCollation() != null) {
        index.append("collation", request.getCollation().asDocument());
    }
    return index;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonDouble(org.bson.BsonDouble)

Aggregations

BsonInt64 (org.bson.BsonInt64)44 BsonDocument (org.bson.BsonDocument)36 BsonString (org.bson.BsonString)30 BsonInt32 (org.bson.BsonInt32)20 BsonArray (org.bson.BsonArray)16 BsonDouble (org.bson.BsonDouble)13 BsonValue (org.bson.BsonValue)11 Test (org.junit.Test)7 MongoNamespace (com.mongodb.MongoNamespace)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 CommandSucceededEvent (com.mongodb.event.CommandSucceededEvent)3 BsonDocumentReader (org.bson.BsonDocumentReader)3 BsonRegularExpression (org.bson.BsonRegularExpression)3 ObjectId (org.bson.types.ObjectId)3 Test (org.junit.jupiter.api.Test)3 SingleMapReaderImpl (org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl)2 BsonBoolean (org.bson.BsonBoolean)2 BsonDateTime (org.bson.BsonDateTime)2 BsonNull (org.bson.BsonNull)2