Search in sources :

Example 26 with BsonDocument

use of org.bson.BsonDocument 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 27 with BsonDocument

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

the class CollectionHelper method aggregate.

public <D> List<D> aggregate(final List<Bson> pipeline, final Decoder<D> decoder) {
    List<BsonDocument> bsonDocumentPipeline = new ArrayList<BsonDocument>();
    for (Bson cur : pipeline) {
        bsonDocumentPipeline.add(cur.toBsonDocument(Document.class, registry));
    }
    BatchCursor<D> cursor = new AggregateOperation<D>(namespace, bsonDocumentPipeline, decoder).execute(getBinding());
    List<D> results = new ArrayList<D>();
    while (cursor.hasNext()) {
        results.addAll(cursor.next());
    }
    return results;
}
Also used : BsonDocument(org.bson.BsonDocument) ArrayList(java.util.ArrayList) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) Bson(org.bson.conversions.Bson)

Example 28 with BsonDocument

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

the class TestCommandListener method getWritableClone.

private BsonDocument getWritableClone(final BsonDocument original) {
    BsonDocument clone = new BsonDocument();
    BsonDocumentWriter writer = new BsonDocumentWriter(clone);
    new BsonDocumentCodec(CODEC_REGISTRY_HACK).encode(writer, original, EncoderContext.builder().build());
    return clone;
}
Also used : BsonDocument(org.bson.BsonDocument) BsonDocumentWriter(org.bson.BsonDocumentWriter) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec)

Example 29 with BsonDocument

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

the class ConnectionStringTest method assertExpectedHosts.

private void assertExpectedHosts(final List<String> hosts) {
    List<String> cleanedHosts = new ArrayList<String>();
    for (String host : hosts) {
        if (host.startsWith("[")) {
            int idx = host.indexOf("]");
            cleanedHosts.add(host.substring(1, idx) + host.substring(idx + 1));
        } else {
            cleanedHosts.add(host);
        }
    }
    List<String> expectedHosts = new ArrayList<String>();
    for (BsonValue rawHost : definition.getArray("hosts")) {
        BsonDocument hostDoc = rawHost.asDocument();
        String host = hostDoc.getString("host").getValue();
        String port = "";
        if (!hostDoc.get("port").isNull()) {
            port = ":" + hostDoc.getInt32("port").getValue();
        }
        expectedHosts.add(host + port);
    }
    assertEquals(expectedHosts, cleanedHosts);
}
Also used : BsonDocument(org.bson.BsonDocument) ArrayList(java.util.ArrayList) ConnectionString(com.mongodb.ConnectionString) BsonValue(org.bson.BsonValue)

Example 30 with BsonDocument

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

the class ClusterFixture method enableMaxTimeFailPoint.

public static void enableMaxTimeFailPoint() {
    assumeThat(isSharded(), is(false));
    new CommandWriteOperation<BsonDocument>("admin", new BsonDocumentWrapper<Document>(new Document("configureFailPoint", "maxTimeAlwaysTimeOut").append("mode", "alwaysOn"), new DocumentCodec()), new BsonDocumentCodec()).execute(getBinding());
}
Also used : BsonDocument(org.bson.BsonDocument) DocumentCodec(org.bson.codecs.DocumentCodec) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec) BsonDocumentWrapper(org.bson.BsonDocumentWrapper) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) BsonDocumentCodec(org.bson.codecs.BsonDocumentCodec)

Aggregations

BsonDocument (org.bson.BsonDocument)166 BsonString (org.bson.BsonString)53 BsonValue (org.bson.BsonValue)37 Test (org.junit.Test)34 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 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 Document (org.bson.Document)5 ObjectId (org.bson.types.ObjectId)5