Java Code Examples for com.mongodb.client.MongoDatabase#drop()
The following examples show how to use
com.mongodb.client.MongoDatabase#drop() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoSourceConnectorTest.java From mongo-kafka with Apache License 2.0 | 5 votes |
@Test @DisplayName("Ensure source loads data from MongoClient") void testSourceLoadsDataFromMongoClient() { assumeTrue(isGreaterThanThreeDotSix()); addSourceConnector(); MongoDatabase db1 = getDatabaseWithPostfix(); MongoDatabase db2 = getDatabaseWithPostfix(); MongoDatabase db3 = getDatabaseWithPostfix(); MongoCollection<Document> coll1 = db1.getCollection("coll"); MongoCollection<Document> coll2 = db2.getCollection("coll"); MongoCollection<Document> coll3 = db3.getCollection("coll"); MongoCollection<Document> coll4 = db1.getCollection("db1Coll2"); insertMany(rangeClosed(1, 50), coll1, coll2); assertAll( () -> assertProduced(createInserts(1, 50), coll1), () -> assertProduced(createInserts(1, 50), coll2), () -> assertProduced(emptyList(), coll3)); db1.drop(); insertMany(rangeClosed(51, 60), coll2, coll4); insertMany(rangeClosed(1, 70), coll3); assertAll( () -> assertProduced( concat(createInserts(1, 50), singletonList(createDropCollection())), coll1), () -> assertProduced(createInserts(1, 60), coll2), () -> assertProduced(createInserts(1, 70), coll3), () -> assertProduced(createInserts(51, 60), coll4)); }
Example 2
Source File: MongoSourceConnectorTest.java From mongo-kafka with Apache License 2.0 | 5 votes |
@Test @DisplayName("Ensure source loads data from MongoClient with copy existing data") void testSourceLoadsDataFromMongoClientWithCopyExisting() { assumeTrue(isGreaterThanThreeDotSix()); Properties sourceProperties = new Properties(); sourceProperties.put(MongoSourceConfig.COPY_EXISTING_CONFIG, "true"); addSourceConnector(sourceProperties); MongoDatabase db1 = getDatabaseWithPostfix(); MongoDatabase db2 = getDatabaseWithPostfix(); MongoDatabase db3 = getDatabaseWithPostfix(); MongoCollection<Document> coll1 = db1.getCollection("coll"); MongoCollection<Document> coll2 = db2.getCollection("coll"); MongoCollection<Document> coll3 = db3.getCollection("coll"); MongoCollection<Document> coll4 = db1.getCollection("db1Coll2"); insertMany(rangeClosed(1, 50), coll1, coll2); assertAll( () -> assertProduced(createInserts(1, 50), coll1), () -> assertProduced(createInserts(1, 50), coll2), () -> assertProduced(emptyList(), coll3)); db1.drop(); insertMany(rangeClosed(51, 60), coll2, coll4); insertMany(rangeClosed(1, 70), coll3); assertAll( () -> assertProduced( concat(createInserts(1, 50), singletonList(createDropCollection())), coll1), () -> assertProduced(createInserts(1, 60), coll2), () -> assertProduced(createInserts(1, 70), coll3), () -> assertProduced(createInserts(51, 60), coll4)); }
Example 3
Source File: MongoDatabaseDrop.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public cfData execute(cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException { MongoDatabase db = getMongoDatabase( _session, argStruct ); try{ db.drop(); return cfBooleanData.TRUE; } catch (MongoException me){ throwException(_session, me.getMessage()); return null; } }
Example 4
Source File: DatabaseTools.java From socialite with Apache License 2.0 | 5 votes |
public static void dropDatabaseByURI(MongoClientURI uri, String dbName) throws UnknownHostException{ MongoClient client = new MongoClient(uri); MongoDatabase database = client.getDatabase(dbName); database.drop(); client.close(); }
Example 5
Source File: MongoSourceConnectorTest.java From mongo-kafka with Apache License 2.0 | 4 votes |
@Test @DisplayName("Ensure source can handle non existent database and survive dropping") void testSourceCanHandleNonExistentDatabaseAndSurviveDropping() throws InterruptedException { assumeTrue(isGreaterThanThreeDotSix()); try (KafkaConsumer<?, ?> consumer = createConsumer()) { Pattern pattern = Pattern.compile(format("^%s.*", getDatabaseName())); consumer.subscribe(pattern); MongoDatabase db = getDatabaseWithPostfix(); MongoCollection<Document> coll1 = db.getCollection("coll1"); MongoCollection<Document> coll2 = db.getCollection("coll2"); MongoCollection<Document> coll3 = db.getCollection("coll3"); db.drop(); Properties sourceProperties = new Properties(); sourceProperties.put(MongoSourceConfig.DATABASE_CONFIG, db.getName()); addSourceConnector(sourceProperties); Thread.sleep(5000); assertAll( () -> assertProduced(emptyList(), coll1), () -> assertProduced(emptyList(), coll2), () -> assertProduced(emptyList(), coll3), () -> assertProduced(emptyList(), db.getName())); insertMany(rangeClosed(1, 50), coll1, coll2); insertMany(rangeClosed(1, 1), coll3); assertAll( () -> assertProduced(createInserts(1, 50), coll1), () -> assertProduced(createInserts(1, 50), coll2), () -> assertProduced(singletonList(createInsert(1)), coll3), () -> assertProduced(emptyList(), db.getName())); db.drop(); assertAll( () -> assertProduced( concat(createInserts(1, 50), singletonList(createDropCollection())), coll1), () -> assertProduced( concat(createInserts(1, 50), singletonList(createDropCollection())), coll2), () -> assertProduced(asList(createInsert(1), createDropCollection()), coll3), () -> assertProduced(singletonList(createDropDatabase()), db.getName())); insertMany(rangeClosed(51, 100), coll1, coll2, coll3); assertAll( () -> assertProduced( concat( createInserts(1, 50), singletonList(createDropCollection()), createInserts(51, 100)), coll1), () -> assertProduced( concat( createInserts(1, 50), singletonList(createDropCollection()), createInserts(51, 100)), coll2), () -> assertProduced( concat(asList(createInsert(1), createDropCollection()), createInserts(51, 100)), coll3), () -> assertProduced(singletonList(createDropDatabase()), db.getName())); } }
Example 6
Source File: MongoDocumentStorage.java From lumongo with Apache License 2.0 | 4 votes |
@Override public void drop() { MongoDatabase db = mongoClient.getDatabase(database); db.drop(); }
Example 7
Source File: GetMongoIT.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testDatabaseEL() { runner.clearTransferState(); runner.removeVariable("collection"); runner.removeVariable("db"); runner.setIncomingConnection(true); String[] collections = new String[] { "a", "b", "c" }; String[] dbs = new String[] { "el_db_1", "el_db_2", "el_db_3" }; String query = "{}"; for (int x = 0; x < collections.length; x++) { MongoDatabase db = mongoClient.getDatabase(dbs[x]); db.getCollection(collections[x]) .insertOne(new Document().append("msg", "Hello, World")); Map<String, String> attrs = new HashMap<>(); attrs.put("db", dbs[x]); attrs.put("collection", collections[x]); runner.enqueue(query, attrs); runner.run(); db.drop(); runner.assertTransferCount(GetMongo.REL_SUCCESS, 1); runner.assertTransferCount(GetMongo.REL_ORIGINAL, 1); runner.assertTransferCount(GetMongo.REL_FAILURE, 0); runner.clearTransferState(); } Map<String, Map<String, String>> vals = new HashMap<String, Map<String, String>>(){{ put("Collection", new HashMap<String, String>(){{ put("db", "getmongotest"); put("collection", ""); }}); put("Database", new HashMap<String, String>(){{ put("db", ""); put("collection", "test"); }}); }}; TestRunner tmpRunner; for (Map.Entry<String, Map<String, String>> entry : vals.entrySet()) { // Creating a new runner for each set of attributes map since every subsequent runs will attempt to take the top most enqueued FlowFile tmpRunner = TestRunners.newTestRunner(GetMongo.class); tmpRunner.setProperty(AbstractMongoProcessor.URI, MONGO_URI); tmpRunner.setProperty(AbstractMongoProcessor.DATABASE_NAME, DB_NAME); tmpRunner.setProperty(AbstractMongoProcessor.COLLECTION_NAME, COLLECTION_NAME); tmpRunner.setIncomingConnection(true); tmpRunner.enqueue("{ }", entry.getValue()); try { tmpRunner.run(); } catch (Throwable ex) { Throwable cause = ex.getCause(); Assert.assertTrue(cause instanceof ProcessException); Assert.assertTrue(entry.getKey(), ex.getMessage().contains(entry.getKey())); } tmpRunner.clearTransferState(); } }
Example 8
Source File: TestBase.java From morphia with Apache License 2.0 | 4 votes |
protected void cleanup() { MongoDatabase db = getDatabase(); if (db != null) { db.drop(); } }