本文整理汇总了Java中com.mongodb.MongoClient.getDatabase方法的典型用法代码示例。如果您正苦于以下问题:Java MongoClient.getDatabase方法的具体用法?Java MongoClient.getDatabase怎么用?Java MongoClient.getDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.MongoClient
的用法示例。
在下文中一共展示了MongoClient.getDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: failedInputOfComment
import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Test
public void failedInputOfComment() throws IOException {
String json = "{ plantId: \"58d1c36efb0cac4e15afd27\", comment : \"Here is our comment for this test\" }";
assertFalse(plantController.addComment(json, "second uploadId"));
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase(databaseName);
MongoCollection<Document> plants = db.getCollection("plants");
FindIterable findIterable = plants.find();
Iterator iterator = findIterable.iterator();
while(iterator.hasNext()){
Document plant = (Document) iterator.next();
List<Document> plantComments = (List<Document>) ((Document) plant.get("metadata")).get("comments");
assertEquals(0,plantComments.size());
}
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:19,代码来源:TestPlantComment.java
示例2: MongoConnector
import com.mongodb.MongoClient; //导入方法依赖的package包/类
private MongoConnector(String connectURIStr) throws DiagnosticException {
MongoClientURI clientURI = new MongoClientURI(connectURIStr);
client = new MongoClient(clientURI);
String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase();
db = client.getDatabase(dbName);
}
示例3: UserController
import com.mongodb.MongoClient; //导入方法依赖的package包/类
public UserController(String dbName) throws IOException {
// Set up our server address
// (Default host: 'localhost', default port: 27017)
// ServerAddress testAddress = new ServerAddress();
// Try connecting to the server
//MongoClient mongoClient = new MongoClient(testAddress, credentials);
MongoClient mongoClient = new MongoClient(); // Defaults!
// Try connecting to a database
MongoDatabase db = mongoClient.getDatabase(dbName);
userCollection = db.getCollection("users");
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:15,代码来源:UserController.java
示例4: connect
import com.mongodb.MongoClient; //导入方法依赖的package包/类
private static void connect(String URI){
//Change MongoDB's logger settings
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
rootLogger = loggerContext.getLogger("org.mongodb.driver");
rootLogger.setLevel(Level.INFO);
//Setup Connection
MongoClientURI connectionString = new MongoClientURI(URI);
MongoClient mongoClient = new MongoClient(connectionString);
MongoDatabase database = mongoClient.getDatabase("media_information_service_db");
collection = database.getCollection("messages");
}
示例5: clearAndPopulateDB
import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Before
public void clearAndPopulateDB() {
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase("testingdb");
userDocuments = db.getCollection("users");
userDocuments.drop();
List<Document> testUsers = new ArrayList<>();
testUsers.add(Document.parse("{\n" +
" name: \"Chris\",\n" +
" age: 25,\n" +
" company: \"UMM\",\n" +
" email: \"[email protected]\"\n" +
" }"));
testUsers.add(Document.parse("{\n" +
" name: \"Pat\",\n" +
" age: 37,\n" +
" company: \"IBM\",\n" +
" email: \"[email protected]\"\n" +
" }"));
testUsers.add(Document.parse("{\n" +
" name: \"Jamie\",\n" +
" age: 37,\n" +
" company: \"Frogs, Inc.\",\n" +
" email: \"[email protected]\"\n" +
" }"));
userDocuments.insertMany(testUsers);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:28,代码来源:MongoSpec.java
示例6: main
import com.mongodb.MongoClient; //导入方法依赖的package包/类
public static void main(String args[]) {
ConsoleLogger cl = new ConsoleLogger("test");
cl.setDebugable(true);
UAVServer.instance().setLog(cl);
UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);
MongoClientHookProxy p = new MongoClientHookProxy("test", Collections.emptyMap());
p.doInstallDProxy(null, "testApp");
MongoClient client = new MongoClient();
client.listDatabaseNames().first();
MongoDatabase db = client.getDatabase("apphubDataStore");
db.listCollectionNames().first();
MongoCollection<Document> collection = db.getCollection("test");
collection.listIndexes().first();
Document doc = new Document("name", "Amarcord Pizzeria")
.append("contact",
new Document("phone", "264-555-0193").append("email", "[email protected]")
.append("location", Arrays.asList(-73.88502, 40.749556)))
.append("stars", 2).append("categories", Arrays.asList("Pizzeria", "Italian", "Pasta"));
collection.insertOne(doc);
collection.find().first();
MongoClient client2 = new MongoClient("localhost:27017");
db = client2.getDatabase("apphubDataStore");
db.listCollectionNames().first();
collection = db.getCollection("test");
collection.listIndexes().first();
client.close();
client2.close();
}
示例7: testMongo1
import com.mongodb.MongoClient; //导入方法依赖的package包/类
@POST
@Path("testMongo1")
public void testMongo1(String jsonString) {
MongoClient client = new MongoClient();
client.listDatabaseNames().first();
MongoDatabase db = client.getDatabase("apphubDataStore");
db.listCollectionNames().first();
MongoCollection<Document> collection = db.getCollection("test");
collection.listIndexes().first();
Document doc = new Document("name", "Amarcord Pizzeria")
.append("contact",
new Document("phone", "264-555-0193").append("email", "[email protected]")
.append("location", Arrays.asList(-73.88502, 40.749556)))
.append("stars", 2).append("categories", Arrays.asList("Pizzeria", "Italian", "Pasta"));
collection.insertOne(doc);
collection.find().first();
MongoClient client2 = new MongoClient("localhost:27017");
db = client2.getDatabase("apphubDataStore");
db.listCollectionNames().first();
collection = db.getCollection("test");
collection.listIndexes().first();
client.close();
client2.close();
}
示例8: testUnsetUpdate
import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Test
public void testUnsetUpdate() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new UpdateMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.UPDATE_QUERY_KEYS, "d.id");
runner.setProperty(MongoProps.UPDATE_KEYS, "d.g");
runner.setProperty(MongoProps.UPDATE_OPERATOR, "$unset");
String contents = FileUtils.readFileToString(Paths.get("src/test/resources/update_payload.json").toFile());
runner.enqueue(contents.getBytes());
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 0);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 1);
// Verify whether the update was made
MongoClient client = mongo.getMongoClient();
MongoDatabase db = client.getDatabase(MONGO_DATABASE_NAME);
if (db != null) {
MongoCollection<Document> collection = db.getCollection("insert_test");
Document query = buildQuery("d.id", (JsonObject) JSON_PROVIDER.parse(contents));
assertEquals(collection.count(query.append("d.g", new Document("$exists", true))), 0);
}
}
示例9: run
import com.mongodb.MongoClient; //导入方法依赖的package包/类
/**
* Konstruktor stellt Verbindung zu MongoDB-Server her
* @param host Die Adresse des Servers.
* @param database Die zu benutzende Datenbank.
* @param user Der zu benutzende Benutzer.
* @param password Das zu benutzende Passwort des Benutzers.
*/
public void run()
{
System.out.println("Starting MongoDB Manager...");
// Es wird ein neuer MongoClient mit den Parametern host, database, user und password erstellt
MongoClientURI uri = new MongoClientURI("mongodb://" + user + ":" + password + "@" + host + "/" + database); //
client = new MongoClient(uri);
// Es wird die Datenbank mit dem Wert der Variable
db = client.getDatabase(database);
if(db.getCollection("ratings") == null) db.createCollection("ratings");
}
示例10: MongoBulkWriter
import com.mongodb.MongoClient; //导入方法依赖的package包/类
public MongoBulkWriter(String URI, String namespace)
{
logger = LoggerFactory.getLogger(MongoBulkWriter.class);
logger.info("Connecting to " + URI );
mongoClient = new MongoClient(new MongoClientURI(URI));
String[] parts = namespace.split("\\.");
db = mongoClient.getDatabase(parts[0]);
collection = db.getCollection(parts[1]);
ops = new ArrayList<WriteModel<Document>>();
}
示例11: getScanStats
import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Override
public ScanStats getScanStats() {
try{
MongoClient client = storagePlugin.getClient();
MongoDatabase db = client.getDatabase(scanSpec.getDbName());
MongoCollection<Document> collection = db.getCollection(scanSpec
.getCollectionName());
String json = collection.find().first().toJson();
float approxDiskCost = json.getBytes().length * collection.count();
return new ScanStats(GroupScanProperty.EXACT_ROW_COUNT,
collection.count(), 1, approxDiskCost);
} catch (Exception e) {
throw new DrillRuntimeException(e.getMessage(), e);
}
}
示例12: populateDatabase
import com.mongodb.MongoClient; //导入方法依赖的package包/类
public void populateDatabase(String[][] cellValues, String uploadID){
MongoClient mongoClient = new MongoClient();
MongoDatabase test = mongoClient.getDatabase(databaseName);
MongoCollection plants = test.getCollection("plants");
String[] keys = getKeys(cellValues);
for (int i = 4; i < cellValues.length; i++){
Document doc = new Document();
for(int j = 0; j < cellValues[i].length; j++){
doc.append(keys[j], cellValues[i][j]);
}
if(doc.get("gardenLocation").equals(""))
continue;
// Initialize the empty metadata
Document metadataDoc = new Document();
metadataDoc.append("visits", new BsonArray());
metadataDoc.append("ratings", new BsonArray());
metadataDoc.append("comments", new BsonArray());
doc.append("metadata", metadataDoc);
doc.append("uploadID", uploadID);
doc.append("photoLocation","");
plants.insertOne(doc);
}
setLiveUploadID(uploadID);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:35,代码来源:ExcelParser.java
示例13: testUploadFile
import com.mongodb.MongoClient; //导入方法依赖的package包/类
@Test
public void testUploadFile() {
String filePath = "/IDPH_STD_Illinois_By_County_By_Sex.xlsx";
Object object = new Object();
InputStream excelFile = object.getClass().getResourceAsStream(filePath);
flowerController.uploadFile(excelFile);
MongoClient mongoClient = new MongoClient();
MongoDatabase ddg = mongoClient.getDatabase("ddg");
MongoCollection flowers = ddg.getCollection("flowers");
assertEquals(1664, flowers.count());
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:14,代码来源:FlowerControllerSpec.java
示例14: MongoMain
import com.mongodb.MongoClient; //导入方法依赖的package包/类
MongoMain() {
mongo = new MongoClient("localhost", 27017);
mongoDatabase = mongo.getDatabase("testdb"); //create if not exist
}
示例15: SimpleMongodbAccessor
import com.mongodb.MongoClient; //导入方法依赖的package包/类
public SimpleMongodbAccessor(String ip, int port, String databaseName) {
mongoClient = new MongoClient(ip, port);
mongoDatabase = mongoClient.getDatabase(databaseName);
}