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;
}
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;
}
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;
}
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);
}
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());
}
Aggregations