Search in sources :

Example 1 with BsonInt64

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

the class GetMoreProtocol method asGetMoreCommandResponseDocument.

private BsonDocument asGetMoreCommandResponseDocument(final QueryResult<T> queryResult, final ResponseBuffers responseBuffers) {
    List<ByteBufBsonDocument> rawResultDocuments = Collections.emptyList();
    if (responseBuffers.getReplyHeader().getNumberReturned() != 0) {
        responseBuffers.getBodyByteBuffer().position(0);
        rawResultDocuments = ByteBufBsonDocument.create(responseBuffers);
    }
    BsonDocument cursorDocument = new BsonDocument("id", queryResult.getCursor() == null ? new BsonInt64(0) : new BsonInt64(queryResult.getCursor().getId())).append("ns", new BsonString(namespace.getFullName())).append("nextBatch", 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 2 with BsonInt64

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

the class GridFSTest method processFiles.

private List<BsonDocument> processFiles(final BsonArray bsonArray, final List<BsonDocument> documents) {
    for (BsonValue rawDocument : bsonArray.getValues()) {
        if (rawDocument.isDocument()) {
            BsonDocument document = rawDocument.asDocument();
            if (document.get("length").isInt32()) {
                document.put("length", new BsonInt64(document.getInt32("length").getValue()));
            }
            if (document.containsKey("metadata") && document.getDocument("metadata").isEmpty()) {
                document.remove("metadata");
            }
            if (document.containsKey("aliases") && document.getArray("aliases").getValues().size() == 0) {
                document.remove("aliases");
            }
            if (document.containsKey("contentType") && document.getString("contentType").getValue().length() == 0) {
                document.remove("contentType");
            }
            documents.add(document);
        }
    }
    return documents;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) BsonValue(org.bson.BsonValue)

Example 3 with BsonInt64

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

the class ListCollectionsOperation method asQueryDocument.

private BsonDocument asQueryDocument(final ConnectionDescription connectionDescription, final ReadPreference readPreference) {
    BsonDocument document = new BsonDocument();
    BsonDocument transformedFilter = null;
    if (filter != null) {
        if (filter.containsKey("name")) {
            if (!filter.isString("name")) {
                throw new IllegalArgumentException("When filtering collections on MongoDB versions < 3.0 the name field " + "must be a string");
            }
            transformedFilter = new BsonDocument();
            transformedFilter.putAll(filter);
            transformedFilter.put("name", new BsonString(format("%s.%s", databaseName, filter.getString("name").getValue())));
        } else {
            transformedFilter = filter;
        }
    }
    BsonDocument indexExcludingRegex = new BsonDocument("name", new BsonRegularExpression("^[^$]*$"));
    BsonDocument query = transformedFilter == null ? indexExcludingRegex : new BsonDocument("$and", new BsonArray(asList(indexExcludingRegex, transformedFilter)));
    document.put("$query", query);
    if (connectionDescription.getServerType() == SHARD_ROUTER && !readPreference.equals(primary())) {
        document.put("$readPreference", readPreference.toDocument());
    }
    if (maxTimeMS > 0) {
        document.put("$maxTimeMS", new BsonInt64(maxTimeMS));
    }
    return document;
}
Also used : BsonInt64(org.bson.BsonInt64) BsonDocument(org.bson.BsonDocument) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) BsonRegularExpression(org.bson.BsonRegularExpression)

Example 4 with BsonInt64

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

the class QueryBatchCursor method asGetMoreCommandDocument.

private BsonDocument asGetMoreCommandDocument() {
    BsonDocument document = new BsonDocument("getMore", new BsonInt64(serverCursor.getId())).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 5 with BsonInt64

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

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