本文整理汇总了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);
}
示例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");
}
示例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");
}
示例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");
}
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}
示例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");
}
示例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);
}
示例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();
}
示例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");
}
示例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());
}
示例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");
}