當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。