public void dropTable(SchemaTableName tableName) { deleteTableMetadata(tableName); getCollection(tableName).drop(); tableCache.invalidate(tableName); }
@Signature public void drop() { getWrappedObject().drop(); }
public Void doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { collection.drop(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Dropped collection [{}]", collection.getNamespace() != null ? collection.getNamespace().getCollectionName() : collectionName); } return null; } });
public static void cleanDatabase(MongoPrimary primary, String dbName) { primary.execute("clean-db", mongo -> { MongoDatabase db1 = mongo.getDatabase(dbName); db1.listCollectionNames().forEach((Consumer<String>) ((String x) -> { logger.info("Removing collection '{}' from database '{}'", x, dbName); db1.getCollection(x).drop(); })); }); } }
protected void storeDocuments(String dbName, String collectionName, String pathOnClasspath) { primary().execute("storing documents", mongo -> { Testing.debug("Storing in '" + dbName + "." + collectionName + "' documents loaded from from '" + pathOnClasspath + "'"); MongoDatabase db1 = mongo.getDatabase(dbName); MongoCollection<Document> coll = db1.getCollection(collectionName); coll.drop(); storeDocuments(coll, pathOnClasspath); }); }
private MongoDatabase addValidation(final Document validator, final String collectionName) { ValidationOptions options = new ValidationOptions() .validator(validator) .validationLevel(ValidationLevel.MODERATE) .validationAction(ValidationAction.ERROR); MongoDatabase database = getMongoClient().getDatabase(TEST_DB_NAME); database.getCollection(collectionName).drop(); database.createCollection(collectionName, new CreateCollectionOptions().validationOptions(options)); return database; }
@Test public void testBypassDocumentValidation() { checkMinServerVersion(3.2); getDs().save(asList(new User("john doe", new Date()), new User("John Doe", new Date()))); MongoDatabase database = getMongoClient().getDatabase(TEST_DB_NAME); database.getCollection("out_users").drop(); database.createCollection("out_users", new CreateCollectionOptions() .validationOptions(new ValidationOptions() .validator(Document.parse("{ \"age\" : { \"gte\" : 13 } }")))); try { getDs() .createAggregation(User.class) .match(getDs().find(User.class).field("name").equal("john doe")) .out("out_users", User.class); fail("Document validation should have complained."); } catch (MongoCommandException e) { // expected } getDs() .createAggregation(User.class) .match(getDs().find(User.class).field("name").equal("john doe")) .out("out_users", User.class, builder() .bypassDocumentValidation(true) .build()); Assert.assertEquals(1, getAds().find("out_users", User.class).count()); }
@Test @SuppressWarnings("deprecation") public void testBulkInsertOld() { this.getAds().insert(asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions().writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(5, getDs().getCollection(TestEntity.class).count()); String name = "some_collection"; MongoCollection<Document> collection = getMongoClient().getDatabase(TEST_DB_NAME).getCollection(name); this.getAds().insert(name, asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions().writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(5, collection.count()); collection.drop(); this.getAds().insert(name, asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), WriteConcern.ACKNOWLEDGED); Assert.assertEquals(5, collection.count()); }
@Test public void testBulkInsert() { this.getAds().insert(asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions().writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(5, getDs().getCollection(TestEntity.class).count()); String name = "some_collection"; MongoCollection<Document> collection = getMongoClient().getDatabase(TEST_DB_NAME).getCollection(name); this.getAds().insert(name, asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions().writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(5, collection.count()); collection.drop(); this.getAds().insert(name, asList(new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity(), new TestEntity()), new InsertOptions() .writeConcern(WriteConcern.ACKNOWLEDGED)); Assert.assertEquals(5, collection.count()); }
@Test public void oldIndexForm() { MongoCollection<Document> indexes = getDatabase().getCollection("indexes"); MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class); indexes.drop(); Index index = new IndexBuilder() .name("index_name") .background(true) .disableValidation(true) .expireAfterSeconds(42) .sparse(true) .unique(true) .value("indexName, -text"); indexHelper.createIndex(indexes, mappedClass, index, false); List<DBObject> indexInfo = getDs().getCollection(IndexedClass.class) .getIndexInfo(); for (DBObject dbObject : indexInfo) { if (dbObject.get("name").equals("index_indexName")) { checkIndex(dbObject); } } }
@Test public void embeddedIndexPartialFilters() { getMorphia().map(FeedEvent.class, InboxEvent.class); getDs().ensureIndexes(); final MongoCollection<Document> inboxEvent = getDatabase().getCollection("InboxEvent"); for (final Document index : inboxEvent.listIndexes()) { if (!"_id_".equals(index.get("name"))) { for (String name : index.get("key", Document.class).keySet()) { Assert.assertTrue("Key names should start with the field name: " + name, name.startsWith("feedEvent.")); } } } // check the logging is disabled inboxEvent.drop(); final Builder builder = MapperOptions .builder(getMorphia().getMapper().getOptions()) .disableEmbeddedIndexes(true); getMorphia().getMapper().setOptions(builder.build()); getDs().ensureIndexes(); Assert.assertNull("No indexes should be generated for InboxEvent", inboxEvent.listIndexes().iterator().tryNext()); }
MongoDatabase db1 = mongo.getDatabase("dbit"); MongoCollection<Document> coll = db1.getCollection("dbz865_my@collection"); coll.drop();
public Void doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { collection.drop(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Dropped collection [{}]", collection.getNamespace() != null ? collection.getNamespace().getCollectionName() : collectionName); } return null; } });
public void removeCollection(ServerConfiguration configuration, final MongoCollection mongoCollection) { Task task = mongoClient -> { MongoDatabase mongoDatabase = mongoCollection.getParentDatabase(); com.mongodb.client.MongoDatabase database = mongoClient.getDatabase(mongoDatabase.getName()); com.mongodb.client.MongoCollection<Document> collection = database.getCollection(mongoCollection.getName()); collection.drop(); }; executeTask(configuration, task); }
MongoDatabase db1 = mongo.getDatabase("dbit"); MongoCollection<Document> coll = db1.getCollection("arbitrary"); coll.drop();
.validationAction(ValidationAction.ERROR); MongoDatabase database = getMongoClient().getDatabase(TEST_DB_NAME); database.getCollection("counts").drop(); database.createCollection("counts", new CreateCollectionOptions().validationOptions(validationOptions));
MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class); indexes.drop(); Index index = new IndexBuilder() .fields(new FieldBuilder()
/** * do 'Drop' operation. * <p> * At the moment, this method always returns 1 because the underlying driver doesn't return any value * after the execution of the command. * * @see <a href ="https://docs.mongodb.com/manual/reference/method/db.collection.drop/">Drop Collection</a> */ private static int doDrop(MongoCollection<Document> collection) { collection.drop(); return 1; }