当前位置: 首页>>代码示例>>Java>>正文


Java MongoClient.getDB方法代码示例

本文整理汇总了Java中com.mongodb.MongoClient.getDB方法的典型用法代码示例。如果您正苦于以下问题:Java MongoClient.getDB方法的具体用法?Java MongoClient.getDB怎么用?Java MongoClient.getDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.MongoClient的用法示例。


在下文中一共展示了MongoClient.getDB方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: jongo

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Bean
public Jongo jongo() {
    MongoCredential credential =
        MongoCredential.createCredential(mongoUser, mongoDatabase,
            mongoPassword.toCharArray());
    ServerAddress serverAddress = new ServerAddress(mongoHost, mongoPort);
    MongoClient mongoClient = new MongoClient(serverAddress,
        new ArrayList<MongoCredential>() {{
            add(credential);
        }});

    DB db = mongoClient.getDB(mongoDatabase);
    return new Jongo(db);
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:15,代码来源:NitriteDataGate.java

示例2: AgentConfigurationRepository

import com.mongodb.MongoClient; //导入方法依赖的package包/类
public AgentConfigurationRepository(){
	MongoClient mongoClient = new MongoClient( 
			Properties.getValue(Dictionary.PROPERTY_MONGODB_HOST), 
			27017);
	DB db = mongoClient.getDB("eim");
	collection = db.getCollection("agentConfiguration");
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:8,代码来源:AgentConfigurationRepository.java

示例3: AgentRepository

import com.mongodb.MongoClient; //导入方法依赖的package包/类
public AgentRepository(){
	MongoClient mongoClient = new MongoClient( 
			Properties.getValue(Dictionary.PROPERTY_MONGODB_HOST), 
			27017);
	DB db = mongoClient.getDB("eim");
	collection = db.getCollection("agent");
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:8,代码来源:AgentRepository.java

示例4: testMongoDBConnect

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Test
public void testMongoDBConnect() throws UnknownHostException {
  MongoClient mongoClient = new MongoClient(new MongoClientURI(MONGO_URI));
  DB database = mongoClient.getDB(DB_NAME);
  DBCollection events = database.getCollection(EVENT_COLLECTION_NAME);
  DBCollection readings = database.getCollection(READING_COLLECTION_NAME);
  try {
    assertFalse("MongoDB Events collection not accessible", events.isCapped());
    assertFalse("MongoDB Readings collection not accessible", readings.isCapped());
  } catch (MongoTimeoutException ex) {
    fail("Mongo DB not available.  Check that Mongo DB has been started");
  }
}
 
开发者ID:edgexfoundry,项目名称:core-data,代码行数:14,代码来源:MongoDBConnectivityTest.java

示例5: connectToDatabase

import com.mongodb.MongoClient; //导入方法依赖的package包/类
public GridFS connectToDatabase(ServerAddress server) {
	MongoCredential credential = MongoCredential.createMongoCRCredential("hive-dataserver", "admin", "hive-dataserver".toCharArray());
	MongoClient mongoClient = new MongoClient(server, Arrays.asList(credential));
	logger.info("got client");
	DB db = mongoClient.getDB("hive-dataserver");
	logger.info("Got DB");
	return new GridFS(db);
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:9,代码来源:DataManager.java

示例6: CommentRepository

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Inject
public CommentRepository(@Named("dbName") String dbName, MongoClient mongoClient) {
    DB mongoDb = mongoClient.getDB(dbName);

    jongo = new Jongo(mongoDb,
            new JacksonMapper.Builder()
                    .registerModule(new Jdk8Module())
                    .registerModule(new JavaTimeModule())
                    .build());
}
 
开发者ID:JeffLeFoll,项目名称:polymer-101-backend,代码行数:11,代码来源:CommentRepository.java

示例7: getMongoDB

import com.mongodb.MongoClient; //导入方法依赖的package包/类
/** Get a connection to Mongo */
public synchronized DB getMongoDB() {
  if (database == null) {
    try {
      MongoClient client = new MongoClient(mongoHostname, mongoPort);
      database = client.getDB("gifts-occasion");
    } catch (UnknownHostException uhe) {
      throw new RuntimeException(uhe);
    }
  }

  return database;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:14,代码来源:MongoAccess.java

示例8: beforeClass

import com.mongodb.MongoClient; //导入方法依赖的package包/类
/** Connect to the Occasions database and set the collection */
@BeforeClass
public static void beforeClass() throws UnknownHostException {
  String method = "beforeClass";
  logger.entering(clazz, method);
  mongoClient = new MongoClient(mongoHostname, mongoPort);
  db = mongoClient.getDB("gifts-occasion");
  collection = db.getCollection("occasions");
  logger.exiting(clazz, method);
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:11,代码来源:OccasionResourceTest.java

示例9: getMongoDB

import com.mongodb.MongoClient; //导入方法依赖的package包/类
/** Get a connection to Mongo */
public synchronized DB getMongoDB() {
  if (database == null) {
    try {
      MongoClient client = new MongoClient(mongoHostname, mongoPort);
      database = client.getDB("gifts-group");
    } catch (UnknownHostException uhe) {
      throw new RuntimeException(uhe);
    }
  }

  return database;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:14,代码来源:MongoAccess.java

示例10: setup

import com.mongodb.MongoClient; //导入方法依赖的package包/类
/** Connect to the Mongo database "groups" */
@BeforeClass
public static void setup() throws UnknownHostException {
  int mongoPort = Integer.parseInt(System.getProperty("mongo.test.port"));
  String mongoHostname = System.getProperty("mongo.test.hostname");
  mongo = new MongoClient(mongoHostname, mongoPort);
  db = mongo.getDB("gifts-group");
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:9,代码来源:GroupResourceTest.java

示例11: start

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Override
public void start() throws IOException {
  MongoClientURI clientURI = new MongoClientURI(mongoURL);
  client = new MongoClient(clientURI);
  DB db = client.getDB(clientURI.getDatabase());
  collection = db.getCollection(clientURI.getCollection());
  collection.setWriteConcern(WriteConcern.JOURNALED);
  DBObject index = new BasicDBObject(1).append(pKey, Integer.valueOf(1));
  collection.createIndex(index);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:11,代码来源:MongoPStoreProvider.java

示例12: init

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void init(Object obj) {
    super.init(obj);
    PropertiesWrapper configPropertieWrapper = (PropertiesWrapper) obj;
    String mongodbHost = configPropertieWrapper.getProperty("mongodb.host");
    int mongodbPort = configPropertieWrapper.getIntProperty("mongodb.port", 27017);
    String mongodbDbName = configPropertieWrapper.getProperty("mongodb.dbname");
    client = new MongoClient(mongodbHost, mongodbPort);
    db = client.getDB(mongodbDbName);
    jongo = new Jongo(db);
    setName("JongoDBService");
    super.setActive();
}
 
开发者ID:zerosoft,项目名称:CodeBroker,代码行数:15,代码来源:JongoDBService.java

示例13: MongoDbConnection

import com.mongodb.MongoClient; //导入方法依赖的package包/类
public MongoDbConnection(final String host, final int port) throws UnknownHostException {
    mongoClient = new MongoClient(host, port);

    // For these tests, the database is going to be protected against writes
    // mongoClient.fsyncAndLock();

    db = mongoClient.getDB(defaultDbName);
    coll = db.getCollection(defaultCollectionName);

    log.debug("Saul: MongoDB connection created");
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:12,代码来源:MongoDbConnection.java

示例14: BlogPostRepository

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Inject
public BlogPostRepository(@Named("dbName") String dbName, MongoClient mongoClient) {
    DB mongoDb = mongoClient.getDB(dbName);

    jongo = new Jongo(mongoDb,
            new JacksonMapper.Builder()
                    .registerModule(new Jdk8Module())
                    .registerModule(new JavaTimeModule())
                    .build());
}
 
开发者ID:JeffLeFoll,项目名称:polymer-101-backend,代码行数:11,代码来源:BlogPostRepository.java

示例15: setup

import com.mongodb.MongoClient; //导入方法依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
  // Open a connection to the Mongo database before the tests start.
  mongo = new MongoClient(mongoHostname, mongoPort);
  database = mongo.getDB("gifts-user");
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:7,代码来源:LoginResourceTest.java


注:本文中的com.mongodb.MongoClient.getDB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。