use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class MapReduceIterableImpl method asReadOperation.
@Override
public ReadOperation<BatchCursor<TResult>> asReadOperation() {
if (inline) {
ReadOperation<MapReduceBatchCursor<TResult>> operation = operations.mapReduce(mapFunction, reduceFunction, finalizeFunction, resultClass, filter, limit, maxTimeMS, jsMode, scope, sort, verbose, collation);
return new WrappedMapReduceReadOperation<TResult>(operation);
} else {
getExecutor().execute(createMapReduceToCollectionOperation(), getReadConcern(), getClientSession());
String dbName = databaseName != null ? databaseName : namespace.getDatabaseName();
FindOptions findOptions = new FindOptions().collation(collation);
Integer batchSize = getBatchSize();
if (batchSize != null) {
findOptions.batchSize(batchSize);
}
return operations.find(new MongoNamespace(dbName, collectionName), new BsonDocument(), resultClass, findOptions);
}
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class AggregateIterableImpl method asReadOperation.
@Override
public ReadOperation<BatchCursor<TResult>> asReadOperation() {
MongoNamespace outNamespace = getOutNamespace();
if (outNamespace != null) {
getExecutor().execute(operations.aggregateToCollection(pipeline, maxTimeMS, allowDiskUse, bypassDocumentValidation, collation, hint, hintString, comment, variables, aggregationLevel), getReadPreference(), getReadConcern(), getClientSession());
FindOptions findOptions = new FindOptions().collation(collation);
Integer batchSize = getBatchSize();
if (batchSize != null) {
findOptions.batchSize(batchSize);
}
return operations.find(outNamespace, new BsonDocument(), resultClass, findOptions);
} else {
return asAggregateOperation();
}
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class ClientEncryptionImpl method createDataKey.
@Override
public BsonBinary createDataKey(final String kmsProvider, final DataKeyOptions dataKeyOptions) {
BsonDocument dataKeyDocument = crypt.createDataKey(kmsProvider, dataKeyOptions);
MongoNamespace namespace = new MongoNamespace(options.getKeyVaultNamespace());
keyVaultClient.getDatabase(namespace.getDatabaseName()).getCollection(namespace.getCollectionName(), BsonDocument.class).withWriteConcern(WriteConcern.MAJORITY).insertOne(dataKeyDocument);
return dataKeyDocument.getBinary("_id");
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class CommandMessage method getExtraElements.
private List<BsonElement> getExtraElements(final SessionContext sessionContext) {
List<BsonElement> extraElements = new ArrayList<BsonElement>();
extraElements.add(new BsonElement("$db", new BsonString(new MongoNamespace(getCollectionName()).getDatabaseName())));
if (sessionContext.getClusterTime() != null) {
extraElements.add(new BsonElement("$clusterTime", sessionContext.getClusterTime()));
}
if (sessionContext.hasSession() && responseExpected) {
extraElements.add(new BsonElement("lsid", sessionContext.getSessionId()));
}
boolean firstMessageInTransaction = sessionContext.notifyMessageSent();
assertFalse(sessionContext.hasActiveTransaction() && sessionContext.isSnapshot());
if (sessionContext.hasActiveTransaction()) {
checkServerVersionForTransactionSupport();
extraElements.add(new BsonElement("txnNumber", new BsonInt64(sessionContext.getTransactionNumber())));
if (firstMessageInTransaction) {
extraElements.add(new BsonElement("startTransaction", BsonBoolean.TRUE));
addReadConcernDocument(extraElements, sessionContext);
}
extraElements.add(new BsonElement("autocommit", BsonBoolean.FALSE));
} else if (sessionContext.isSnapshot()) {
addReadConcernDocument(extraElements, sessionContext);
}
if (serverApi != null) {
addServerApiElements(extraElements);
}
if (readPreference != null) {
if (!readPreference.equals(primary())) {
extraElements.add(new BsonElement("$readPreference", readPreference.toDocument()));
} else if (isDirectConnectionToReplicaSetMember()) {
extraElements.add(new BsonElement("$readPreference", primaryPreferred().toDocument()));
}
}
return extraElements;
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class UnifiedTest method addInitialData.
private void addInitialData() {
for (BsonValue cur : initialData.getValues()) {
BsonDocument curDataSet = cur.asDocument();
CollectionHelper<BsonDocument> helper = new CollectionHelper<>(new BsonDocumentCodec(), new MongoNamespace(curDataSet.getString("databaseName").getValue(), curDataSet.getString("collectionName").getValue()));
helper.create(WriteConcern.MAJORITY);
BsonArray documentsArray = curDataSet.getArray("documents", new BsonArray());
if (!documentsArray.isEmpty()) {
helper.insertDocuments(documentsArray.stream().map(BsonValue::asDocument).collect(toList()), WriteConcern.MAJORITY);
}
}
}
Aggregations