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

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

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

Mongo.getDatabaseNames介绍

[英]Gets a list of the names of all databases on the connected server.
[中]获取连接的服务器上所有数据库的名称列表。

代码示例

代码示例来源:origin: restx/restx

@Override
public void check() throws Exception {
  //throws an exception if unhealthy
  mongo.getDatabaseNames();
}

代码示例来源:origin: zscott/MultiBitExchange

private void verifyConnection() {
  mongo.getDatabaseNames();
 }
}

代码示例来源:origin: io.restx/restx-jongo

@Override
public void check() throws Exception {
  //throws an exception if unhealthy
  mongo.getDatabaseNames();
}

代码示例来源:origin: shekhargulati/day13-dropwizard-mongodb-demo-app

@Override
protected Result check() throws Exception {
  mongo.getDatabaseNames();
  return Result.healthy("MongoDB is running... :)");
}

代码示例来源:origin: ch.epfl.bbp.nlp/bluima_mongodb

if (safe)
  m.setWriteConcern(WriteConcern.SAFE);
m.getDatabaseNames();// to test connection
db = m.getDB(dbName);
if (user.length() > 0) {

代码示例来源:origin: colinmarc/zerowing

databases.add(database);
} else {
 databases = mongo.getDatabaseNames();

代码示例来源: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: apache/jackrabbit-oak

private static boolean testMongoAvailability() {
  Mongo mongo = null;
  try {
    MongoClientURI uri = new MongoClientURI(MONGO_URI + "?connectTimeoutMS=3000");
    mongo = new MongoClient(uri);
    mongo.getDatabaseNames();
    return true;
  } catch (Exception e) {
    return false;
  } finally {
    if (mongo != null) {
      mongo.close();
    }
  }
}

代码示例来源: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");
}

相关文章