com.mongodb.Mongo.dropDatabase()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中com.mongodb.Mongo.dropDatabase()方法的一些代码示例,展示了Mongo.dropDatabase()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mongo.dropDatabase()方法的具体详情如下:
包路径:com.mongodb.Mongo
类名称:Mongo
方法名:dropDatabase

Mongo.dropDatabase介绍

[英]Drops the database if it exists.
[中]删除数据库(如果存在)。

代码示例

代码示例来源:origin: apache/attic-polygene-java

@Override
  public void tearDown()
    throws Exception
  {
    mongo.dropDatabase( dbName );
    super.tearDown();
  }
}

代码示例来源:origin: apache/attic-polygene-java

@Override
  public void tearDown()
    throws Exception
  {
    mongo.dropDatabase( dbName );
    super.tearDown();
  }
}

代码示例来源:origin: apache/attic-polygene-java

@Override
  public void tearDown()
    throws Exception
  {
    mongo.dropDatabase( dbName );
    super.tearDown();
  }
}

代码示例来源:origin: org.iternine/jeppetto-test-support

@Override
public void close() {
  if (mongoDbName == null) {
    return;
  }
  
  try {
    Mongo mongo = new Mongo("127.0.0.1", mongoDbPort);
    DB db = mongo.getDB(mongoDbName);
    db.resetError();
    db.dropDatabase();
    DBObject err = db.getLastError();
    if (err != null && err.get("err") != null) {
      logger.error("Could not drop database {}: {}", mongoDbName, err);
    }
    mongo.dropDatabase(mongoDbName);
    if (mongo.getDatabaseNames().contains(mongoDbName)) {
      logger.error("Database {} will not go away!", mongoDbName);
    }
  } catch (UnknownHostException e) {
    // weird
  } catch (MongoException e) {
    logger.warn("Could not drop database {}: {}", mongoDbName, e.getMessage());
  }
}

代码示例来源:origin: eBay/YiDB

@Before
public void setup() {
  Mongo mongo = getDataSource().getMongoInstance();
  mongo.dropDatabase(db);
}

代码示例来源:origin: eBay/YiDB

mongo.dropDatabase(repositoryName);
} catch (MongoException e) {
  throw new MongoOperationException(e);

代码示例来源:origin: eBay/YiDB

@Test
  public void testWrapperUpdate() {
    MongoDataSource ds = getDataSource();
    Mongo mongo = ds.getMongoInstance();
    
    mongo.dropDatabase(DB);
    
    DBCollection coll = mongo.getDB(DB).getCollection(COLL);
    coll.setWriteConcern(WriteConcern.SAFE);
    
    BasicDBObject o1 = new BasicDBObject().append("name", "value");
    coll.insert(o1);
    
    BasicDBObject o2 = new BasicDBObject().append("name", "newValue");
    
    BasicDBObject update = new BasicDBObject().append("$set", 
        o2);
    Assert.assertTrue(MongoUtils.wrapperUpdate(coll, o1, update));
    
    Assert.assertEquals(1, coll.count(o2));
    
    Assert.assertFalse(MongoUtils.wrapperUpdate(coll, o1, update));
    
    
  }
}

代码示例来源:origin: eBay/YiDB

@Test
public void testEnsureIndex() {
  MongoDataSource ds = getDataSource();
  Mongo mongo = ds.getMongoInstance();
  
  mongo.dropDatabase(DB);
  
  DBCollection coll = mongo.getDB(DB).getCollection(COLL);
  MongoUtils.ensureIndex(coll, "fieldName", false, false);
  
  MongoUtils.ensureIndex(coll, "fieldName", true, false);
  
  MongoUtils.ensureIndex(coll, "fieldName", true, true);
  
  MongoUtils.ensureIndex(coll, "fieldName", false, true);
}

代码示例来源:origin: liveoak-io/liveoak

@Test
public void dbNameWithSpace() throws Exception {
  // check initial creation
  assertThat(mongoClient.getDatabaseNames().contains("foo bar")).isFalse();
  assertThat(mongoClient.getDatabaseNames().contains("foo%20bar")).isFalse();
  ResourceState config = new DefaultResourceState();
  config.putProperty("db", "foo bar");
  setUpSystem(config);
  // check via reading from LiveOak
  ResourceState result = client.read(new RequestContext.Builder().build(), ADMIN_PATH);
  assertThat(result.getProperty("db")).isEqualTo("foo bar");
  // we need to write something to the database, otherwise its not created in the database server
  client.create(new RequestContext.Builder().build(), "/testApp/storage/", new DefaultResourceState());
  // check via what is in mongo
  assertThat(mongoClient.getDatabaseNames().contains("foo%20bar")).isTrue();
  assertThat(mongoClient.getDatabaseNames().contains("foo bar")).isFalse();
  mongoClient.dropDatabase("foo%20bar");
  // check on update
  result.putProperty("db", "hello <world>");
  ResourceState updatedResult = client.update(new RequestContext.Builder().build(), ADMIN_PATH, result);
  assertThat(updatedResult.getProperty("db")).isEqualTo("hello <world>");
  // check what is in mongo
  assertThat(mongoClient.getDatabaseNames().contains("hello%20%3Cworld%3E")).isTrue();
  assertThat(mongoClient.getDatabaseNames().contains("foo <world>")).isFalse();
  mongoClient.dropDatabase("hello%20%3Cworld%3E");
}

相关文章