use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class MapReduceIterableImpl method execute.
MongoIterable<TResult> execute() {
if (inline) {
MapReduceWithInlineResultsOperation<TResult> operation = new MapReduceWithInlineResultsOperation<TResult>(namespace, new BsonJavaScript(mapFunction), new BsonJavaScript(reduceFunction), codecRegistry.get(resultClass)).filter(toBsonDocument(filter)).limit(limit).maxTime(maxTimeMS, MILLISECONDS).jsMode(jsMode).scope(toBsonDocument(scope)).sort(toBsonDocument(sort)).verbose(verbose).readConcern(readConcern).collation(collation);
if (finalizeFunction != null) {
operation.finalizeFunction(new BsonJavaScript(finalizeFunction));
}
return new OperationIterable<TResult>(operation, readPreference, executor);
} else {
MapReduceToCollectionOperation operation = createMapReduceToCollectionOperation();
String dbName = databaseName != null ? databaseName : namespace.getDatabaseName();
MongoIterable<TResult> delegated = new FindIterableImpl<TDocument, TResult>(new MongoNamespace(dbName, collectionName), documentClass, resultClass, codecRegistry, primary(), readConcern, executor, new BsonDocument(), new FindOptions().collation(collation)).batchSize(batchSize);
return new AwaitingWriteOperationIterable<TResult, MapReduceStatistics>(operation, executor, delegated);
}
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class CollectionAcceptanceTest method shouldChangeACollectionNameWhenRenameIsCalled.
@Test
public void shouldChangeACollectionNameWhenRenameIsCalled() {
//given
collection.insertOne(new Document("someKey", "someValue"));
assertThat(database.listCollectionNames().into(new ArrayList<String>()).contains(getCollectionName()), is(true));
//when
String newCollectionName = "TheNewCollectionName";
collection.renameCollection(new MongoNamespace(getDatabaseName(), newCollectionName));
//then
assertThat(database.listCollectionNames().into(new ArrayList<String>()).contains(getCollectionName()), is(false));
assertThat(database.listCollectionNames().into(new ArrayList<String>()).contains(newCollectionName), is(true));
MongoCollection<Document> renamedCollection = database.getCollection(newCollectionName);
assertThat("Renamed collection should have the same number of documents as original", renamedCollection.count(), is(1L));
}
use of com.mongodb.MongoNamespace in project incubator-rya by apache.
the class AggregationPipelineQueryNodeTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() {
collection = Mockito.mock(MongoCollection.class);
Mockito.when(collection.getNamespace()).thenReturn(new MongoNamespace("db", "collection"));
}
use of com.mongodb.MongoNamespace in project incubator-rya by apache.
the class SparqlToPipelineTransformVisitorTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() {
collection = Mockito.mock(MongoCollection.class);
Mockito.when(collection.getNamespace()).thenReturn(new MongoNamespace("db", "collection"));
}
use of com.mongodb.MongoNamespace in project mongo-java-driver by mongodb.
the class AbstractClientSideEncryptionTest method setUp.
@Before
public void setUp() {
assumeTrue("Client side encryption tests disabled", hasEncryptionTestsEnabled());
assumeFalse("runOn requirements not satisfied", skipTest);
assumeFalse("Skipping count tests", filename.startsWith("count."));
assumeFalse(definition.getString("skipReason", new BsonString("")).getValue(), definition.containsKey("skipReason"));
String databaseName = specDocument.getString("database_name").getValue();
String collectionName = specDocument.getString("collection_name").getValue();
collectionHelper = new CollectionHelper<BsonDocument>(new BsonDocumentCodec(), new MongoNamespace(databaseName, collectionName));
MongoDatabase database = getMongoClient().getDatabase(databaseName);
MongoCollection<BsonDocument> collection = database.getCollection(collectionName, BsonDocument.class);
collection.drop();
/* Create the collection for auto encryption. */
if (specDocument.containsKey("json_schema")) {
database.createCollection(collectionName, new CreateCollectionOptions().validationOptions(new ValidationOptions().validator(new BsonDocument("$jsonSchema", specDocument.getDocument("json_schema")))));
}
/* Insert data into the collection */
List<BsonDocument> documents = new ArrayList<BsonDocument>();
if (!data.isEmpty()) {
for (BsonValue document : data) {
documents.add(document.asDocument());
}
database.getCollection(collectionName, BsonDocument.class).insertMany(documents);
}
/* Insert data into the "keyvault.datakeys" key vault. */
BsonArray data = specDocument.getArray("key_vault_data", new BsonArray());
collection = getMongoClient().getDatabase("keyvault").getCollection("datakeys", BsonDocument.class).withWriteConcern(WriteConcern.MAJORITY);
collection.drop();
if (!data.isEmpty()) {
documents = new ArrayList<BsonDocument>();
for (BsonValue document : data) {
documents.add(document.asDocument());
}
collection.insertMany(documents);
}
commandListener = new TestCommandListener();
BsonDocument clientOptions = definition.getDocument("clientOptions");
BsonDocument cryptOptions = clientOptions.getDocument("autoEncryptOpts");
BsonDocument kmsProviders = cryptOptions.getDocument("kmsProviders");
boolean bypassAutoEncryption = cryptOptions.getBoolean("bypassAutoEncryption", BsonBoolean.FALSE).getValue();
Map<String, BsonDocument> namespaceToSchemaMap = new HashMap<String, BsonDocument>();
if (cryptOptions.containsKey("schemaMap")) {
BsonDocument autoEncryptMapDocument = cryptOptions.getDocument("schemaMap");
for (Map.Entry<String, BsonValue> entries : autoEncryptMapDocument.entrySet()) {
final BsonDocument autoEncryptOptionsDocument = entries.getValue().asDocument();
namespaceToSchemaMap.put(entries.getKey(), autoEncryptOptionsDocument);
}
}
Map<String, Object> extraOptions = new HashMap<String, Object>();
if (cryptOptions.containsKey("extraOptions")) {
BsonDocument extraOptionsDocument = cryptOptions.getDocument("extraOptions");
if (extraOptionsDocument.containsKey("mongocryptdSpawnArgs")) {
List<String> mongocryptdSpawnArgsValue = new ArrayList<String>();
for (BsonValue cur : extraOptionsDocument.getArray("mongocryptdSpawnArgs")) {
mongocryptdSpawnArgsValue.add(cur.asString().getValue());
}
extraOptions.put("mongocryptdSpawnArgs", mongocryptdSpawnArgsValue);
}
if (extraOptionsDocument.containsKey("mongocryptdBypassSpawn")) {
extraOptions.put("mongocryptdBypassSpawn", extraOptionsDocument.getBoolean("mongocryptdBypassSpawn").getValue());
}
if (extraOptionsDocument.containsKey("mongocryptdURI")) {
extraOptions.put("mongocryptdURI", extraOptionsDocument.getString("mongocryptdURI").getValue());
}
}
Map<String, Map<String, Object>> kmsProvidersMap = new HashMap<>();
for (String kmsProviderKey : kmsProviders.keySet()) {
BsonDocument kmsProviderOptions = kmsProviders.get(kmsProviderKey).asDocument();
Map<String, Object> kmsProviderMap = new HashMap<>();
kmsProvidersMap.put(kmsProviderKey.startsWith("aws") ? "aws" : kmsProviderKey, kmsProviderMap);
switch(kmsProviderKey) {
case "aws":
kmsProviderMap.put("accessKeyId", System.getProperty("org.mongodb.test.awsAccessKeyId"));
kmsProviderMap.put("secretAccessKey", System.getProperty("org.mongodb.test.awsSecretAccessKey"));
break;
case "awsTemporary":
kmsProviderMap.put("accessKeyId", System.getProperty("org.mongodb.test.tmpAwsAccessKeyId"));
kmsProviderMap.put("secretAccessKey", System.getProperty("org.mongodb.test.tmpAwsSecretAccessKey"));
kmsProviderMap.put("sessionToken", System.getProperty("org.mongodb.test.tmpAwsSessionToken"));
break;
case "awsTemporaryNoSessionToken":
kmsProviderMap.put("accessKeyId", System.getProperty("org.mongodb.test.tmpAwsAccessKeyId"));
kmsProviderMap.put("secretAccessKey", System.getProperty("org.mongodb.test.tmpAwsSecretAccessKey"));
break;
case "azure":
kmsProviderMap.put("tenantId", System.getProperty("org.mongodb.test.azureTenantId"));
kmsProviderMap.put("clientId", System.getProperty("org.mongodb.test.azureClientId"));
kmsProviderMap.put("clientSecret", System.getProperty("org.mongodb.test.azureClientSecret"));
break;
case "gcp":
kmsProviderMap.put("email", System.getProperty("org.mongodb.test.gcpEmail"));
kmsProviderMap.put("privateKey", System.getProperty("org.mongodb.test.gcpPrivateKey"));
break;
case "kmip":
kmsProviderMap.put("endpoint", System.getProperty("org.mongodb.test.kmipEndpoint", "localhost:5698"));
break;
case "local":
kmsProviderMap.put("key", kmsProviderOptions.getBinary("key").getData());
break;
default:
throw new UnsupportedOperationException("Unsupported KMS provider: " + kmsProviderKey);
}
}
String keyVaultNamespace = "keyvault.datakeys";
if (cryptOptions.containsKey("keyVaultNamespace")) {
keyVaultNamespace = cryptOptions.getString("keyVaultNamespace").getValue();
}
createMongoClient(AutoEncryptionSettings.builder().keyVaultNamespace(keyVaultNamespace).kmsProviders(kmsProvidersMap).schemaMap(namespaceToSchemaMap).bypassAutoEncryption(bypassAutoEncryption).extraOptions(extraOptions).build(), commandListener);
database = getDatabase(databaseName);
helper = new JsonPoweredCrudTestHelper(description, database, database.getCollection("default", BsonDocument.class));
}
Aggregations