Java Code Examples for com.mongodb.MongoClient#getDatabase()
The following examples show how to use
com.mongodb.MongoClient#getDatabase() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoDocumentStorage.java From lumongo with Apache License 2.0 | 6 votes |
public MongoDocumentStorage(MongoClient mongoClient, String indexName, String dbName, String rawCollectionName, boolean sharded) { this.mongoClient = mongoClient; this.indexName = indexName; this.database = dbName; this.rawCollectionName = rawCollectionName; MongoDatabase storageDb = mongoClient.getDatabase(database); MongoCollection<Document> coll = storageDb.getCollection(ASSOCIATED_FILES + "." + FILES); coll.createIndex(new Document(ASSOCIATED_METADATA + "." + DOCUMENT_UNIQUE_ID_KEY, 1)); coll.createIndex(new Document(ASSOCIATED_METADATA + "." + FILE_UNIQUE_ID_KEY, 1)); if (sharded) { MongoDatabase adminDb = mongoClient.getDatabase(MongoConstants.StandardDBs.ADMIN); Document enableCommand = new Document(); enableCommand.put(MongoConstants.Commands.ENABLE_SHARDING, database); adminDb.runCommand(enableCommand); shardCollection(storageDb, adminDb, rawCollectionName); shardCollection(storageDb, adminDb, ASSOCIATED_FILES + "." + CHUNKS); } }
Example 2
Source File: MongoDBUtil.java From sockslib with Apache License 2.0 | 6 votes |
/** * Connect MongoDB and call callback, close connection at last. * * @param collectionName Collection name. * @param callback Callback * @param <T> The type of value which you want to return. * @return The value which callback returned. */ public <T> T connect(String collectionName, CollectionCallback<T> callback) { MongoClient client = null; T t = null; try { client = getConnectedClient(); MongoDatabase database = client.getDatabase(databaseName); MongoCollection<Document> collection = database.getCollection(collectionName); t = callback.doInCollection(collection); } finally { if (client != null) { client.close(); } } return t; }
Example 3
Source File: MongoDbSinkTask.java From kafka-connect-mongodb with Apache License 2.0 | 6 votes |
@Override public void start(Map<String, String> props) { LOGGER.info("starting MongoDB sink task"); sinkConfig = new MongoDbSinkConnectorConfig(props); MongoClientURI uri = sinkConfig.buildClientURI(); mongoClient = new MongoClient(uri); database = mongoClient.getDatabase(uri.getDatabase()); remainingRetries = sinkConfig.getInt( MongoDbSinkConnectorConfig.MONGODB_MAX_NUM_RETRIES_CONF); deferRetryMs = sinkConfig.getInt( MongoDbSinkConnectorConfig.MONGODB_RETRIES_DEFER_TIMEOUT_CONF); processorChains = sinkConfig.buildPostProcessorChains(); cdcHandlers = sinkConfig.getCdcHandlers(); writeModelStrategies = sinkConfig.getWriteModelStrategies(); rateLimitSettings = sinkConfig.getRateLimitSettings(); deleteOneModelDefaultStrategies = sinkConfig.getDeleteOneModelDefaultStrategies(); }
Example 4
Source File: Configuration.java From epcis with Apache License 2.0 | 6 votes |
private void setMongoDB(JSONObject json) { if (json.isNull("backend_ip")) { backend_ip = "localhost"; } else { backend_ip = json.getString("backend_ip"); } if (json.isNull("backend_port")) { backend_port = 27017; } else { backend_port = json.getInt("backend_port"); } if (json.isNull("backend_database_name")) { databaseName = "epcis"; } else { databaseName = json.getString("backend_database_name"); } mongoClient = new MongoClient(backend_ip, backend_port); mongoDatabase = mongoClient.getDatabase(databaseName); persistentGraph = new ChronoGraph(backend_ip, backend_port, databaseName); persistentGraphData = new ChronoGraph(backend_ip, backend_port, databaseName + "-data"); }
Example 5
Source File: MDbConnection.java From birt with Eclipse Public License 1.0 | 5 votes |
public static MongoDatabase getMongoDatabase( Properties connProperties ) throws OdaException { MongoClient mongoClient = MongoDBDriver.getMongoNode( connProperties ); // to avoid potential conflict in shared DB, ReadPreference is exposed // as cursorReadPreference in data set property String dbName = MongoDBDriver.getDatabaseName( connProperties ); if( dbName == null || dbName.isEmpty() ) throw new OdaException( Messages.mDbConnection_missingValueDBName ); MongoDatabase dbInstance = null; try { Boolean dbExists = existsDatabase( mongoClient, dbName, connProperties ); if( dbExists != null && !dbExists ) // does not exist for sure { // do not proceed to create new database instance throw new OdaException( Messages.bind( Messages.mDbConnection_invalidDatabaseName, dbName )); } dbInstance = mongoClient.getDatabase( dbName ); authenticateDB( dbInstance, connProperties ); } catch ( Exception ex ) { MongoDBDriver.getLogger( ).log( Level.SEVERE, "Unable to get Database " + dbName + ". " + ex.getMessage( ), ex ); throw new OdaException( ex ); } return dbInstance; }
Example 6
Source File: MongoDbDecorator.java From jpa-unit with Apache License 2.0 | 5 votes |
@Override public void beforeTest(final TestInvocation invocation) throws Exception { final ExecutionContext context = invocation.getContext(); final Configuration configuration = configurationRegistry.getConfiguration(context.getDescriptor()); final MongoClient client = (MongoClient) context.getData(Constants.KEY_MONGO_CLIENT); final MongoDatabase mongoDb = client.getDatabase(configuration.getDatabaseName()); context.storeData(Constants.KEY_MONGO_DB, mongoDb); final MongoDbFeatureExecutor dbFeatureExecutor = new MongoDbFeatureExecutor(invocation.getFeatureResolver()); dbFeatureExecutor.executeBeforeTest(mongoDb); context.storeData(Constants.KEY_FEATURE_EXECUTOR, dbFeatureExecutor); }
Example 7
Source File: MongoDbIO.java From beam with Apache License 2.0 | 5 votes |
private long getEstimatedSizeBytes( MongoClient mongoClient, String database, String collection) { MongoDatabase mongoDatabase = mongoClient.getDatabase(database); // get the Mongo collStats object // it gives the size for the entire collection BasicDBObject stat = new BasicDBObject(); stat.append("collStats", collection); Document stats = mongoDatabase.runCommand(stat); return stats.get("size", Number.class).longValue(); }
Example 8
Source File: MongoNotebookRepo.java From zeppelin with Apache License 2.0 | 5 votes |
@Override public void init(ZeppelinConfiguration zConf) throws IOException { this.conf = zConf; client = new MongoClient(new MongoClientURI(conf.getMongoUri())); db = client.getDatabase(conf.getMongoDatabase()); notes = db.getCollection(conf.getMongoCollection()); folderName = conf.getMongoFolder(); folders = db.getCollection(folderName); if (conf.getMongoAutoimport()) { // import local notes into MongoDB insertFileSystemNotes(); } }
Example 9
Source File: MongoDbProvider.java From swellrt with Apache License 2.0 | 5 votes |
/** * Starts the {@link Mongo} instance and explicitly checks whether it is * actually alive. * * @throws PersistenceStartException if we can't make a connection to MongoDb. */ private void start() { Preconditions.checkState(!isRunning(), "Can't start after a connection has been established"); String host = dbHost; int port = Integer.parseInt(dbPort); mongoClient = new MongoClient(host, port); MongoDatabase database = mongoClient.getDatabase(dbName); isRunning = true; LOG.info("Started MongoDb persistence"); }
Example 10
Source File: DoTestMongoClientProxy.java From uavstack with Apache License 2.0 | 5 votes |
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(); }
Example 11
Source File: MongoSchema.java From calcite with Apache License 2.0 | 5 votes |
/** * Creates a MongoDB schema. * * @param host Mongo host, e.g. "localhost" * @param credential Optional credentials (null for none) * @param options Mongo connection options * @param database Mongo database name, e.g. "foodmart" */ MongoSchema(String host, String database, MongoCredential credential, MongoClientOptions options) { super(); try { final MongoClient mongo = credential == null ? new MongoClient(new ServerAddress(host), options) : new MongoClient(new ServerAddress(host), credential, options); this.mongoDb = mongo.getDatabase(database); } catch (Exception e) { throw new RuntimeException(e); } }
Example 12
Source File: TransformationQueryTestInternal.java From epcis with Apache License 2.0 | 5 votes |
public void test() throws IOException, InterruptedException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); String baseEPC = "urn:epc:id:sgtin:0000001.000001."; MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("test1"); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("edges").createIndex(new BsonDocument("_outV", new BsonInt32(1)) .append("_label", new BsonInt32(1)).append("_t", new BsonInt32(1)).append("_inV", new BsonInt32(1))); client.close(); ChronoGraph g = new ChronoGraph("test1"); for (int i = 0; i < transferCount; i++) { long cTime = System.currentTimeMillis(); g.addTimestampEdgeProperties(baseEPC + i, baseEPC + (2 * i + 1), "transformTo", cTime, new BsonDocument()); g.addTimestampEdgeProperties(baseEPC + i, baseEPC + (2 * i + 2), "transformTo", cTime, new BsonDocument()); Thread.sleep(2000); double avg = doTransformationQuery(g); System.out.println(i + "\t" + avg); bw.write(i + "\t" + avg + "\n"); bw.flush(); } bw.close(); }
Example 13
Source File: PrintMongDB.java From Java-Data-Analysis with MIT License | 5 votes |
public static void main(String[] args) { MongoClient client = new MongoClient("localhost", 27017); MongoDatabase friends = client.getDatabase("friends"); MongoCollection relatives = friends.getCollection("relatives"); Bson bson = Sorts.ascending("fname"); FindIterable<Document> docs = relatives.find().sort(bson); int num = 0; for (Document doc : docs) { String name = doc.getString("fname"); String relation = doc.getString("relation"); System.out.printf("%4d. %s, %s%n", ++num, name, relation); } }
Example 14
Source File: MongoDBConnection.java From nationalparks with Apache License 2.0 | 5 votes |
@PostConstruct public void initConnection() { String mongoHost = env.getProperty("mongodb.server.host", "127.0.0.1"); // env var MONGODB_SERVER_HOST takes precedence String mongoPort = env.getProperty("mongodb.server.port", "27017"); // env var MONGODB_SERVER_PORT takes precedence String mongoUri = env.getProperty("uri", ""); String mongoUser = env.getProperty("mongodb.user", "mongodb"); // env var MONGODB_USER takes precedence String mongoPassword = env.getProperty("mongodb.password", "mongodb"); // env var MONGODB_PASSWORD takes precedence String mongoDBName = env.getProperty("mongodb.database", "mongodb"); // env var MONGODB_DATABASE takes precedence String dbServiceName = env.getProperty("database.service.name", ""); try { // If mongoUri is set, we use this, else, we use mongoHost and mongoPort // This will come in this form (mongodb://127.0.0.1:27017) if (mongoUri!=null && ! "".equals(mongoUri)){ Pattern pattern = Pattern.compile("mongodb?://([^:^/]*):?(\\d*)?"); Matcher matcher = pattern.matcher(mongoUri); if (matcher.find()){ mongoHost = matcher.group(1); mongoPort = matcher.group(2); // We assume all information comes in the binding format mongoUser = env.getProperty("username", "mongodb"); mongoPassword = env.getProperty("password", "mongodb"); mongoDBName = env.getProperty("database_name", "mongodb"); } } else if (dbServiceName !=null && ! "".equals(dbServiceName)) { mongoHost = dbServiceName; } String mongoURI = "mongodb://" + mongoUser + ":" + mongoPassword + "@" + mongoHost + ":" + mongoPort + "/" + mongoDBName; System.out.println("[INFO] Connection string: " + mongoURI); MongoClient mongoClient = new MongoClient(new MongoClientURI(mongoURI)); mongoDB = mongoClient.getDatabase(mongoDBName); } catch (Exception e) { System.out.println("[ERROR] Creating the mongoDB. " + e.getMessage()); mongoDB = null; } }
Example 15
Source File: AggregationQueryTest2.java From epcis with Apache License 2.0 | 4 votes |
public void test() throws IOException, InterruptedException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("epcis"); db.getCollection("EventData").drop(); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("edges").createIndex(new BsonDocument("_outV", new BsonInt32(1)).append("_t", new BsonInt32(1)) .append("_inV", new BsonInt32(1))); client.close(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String cTime = sdf.format(new Date()); long lastTimeMil = System.currentTimeMillis() + 100000000; for (int i = 0; i < transferCount; i++) { Thread.sleep(1000); cTime = sdf.format(new Date()); String epcParent = String.format("%010d", i + 1); String epcChild = String.format("%010d", i); // urn:epc:id:sscc:0000002.0000000001 String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument schemaVersion=\"1.2\"\n" + " creationDate=\"2013-06-04T14:59:02.099+02:00\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\"\n" + " xmlns:example=\"http://ns.example.com/epcis\">\n" + " <EPCISBody>\n" + " <EventList>"; String bottom = "</EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; String body = "<AggregationEvent>\n" + " <eventTime>" + cTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <parentID>urn:epc:id:sscc:0000001." + epcParent + "</parentID>\n" + " <childEPCs>\n" + " <epc>urn:epc:id:sscc:0000001." + epcChild + "</epc>\n" + " </childEPCs>\n" + " <action>ADD</action>\n" + " <bizStep>urn:epcglobal:cbv:bizstep:loading</bizStep>\n" + " <!-- TNT Liverpool depot -->\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:0000001.00002.1</id>\n" + " </bizLocation>\n" + " </AggregationEvent>"; String lastTime = sdf.format(new Date(lastTimeMil - i)); body += "<AggregationEvent>\n" + " <eventTime>" + lastTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <parentID>urn:epc:id:sscc:0000001." + epcParent + "</parentID>\n" + " <childEPCs>\n" + " <epc>urn:epc:id:sscc:0000001." + epcChild + "</epc>\n" + " </childEPCs>\n" + " <action>DELETE</action>\n" + " <bizStep>urn:epcglobal:cbv:bizstep:loading</bizStep>\n" + " <!-- TNT Liverpool depot -->\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:0000001.00002.1</id>\n" + " </bizLocation>\n" + " </AggregationEvent>"; EventCapture cap = new EventCapture(); cap.capture(top + body + bottom); Thread.sleep(3000); int avg = doTransformationQuery(); System.out.println(i + "\t" + avg); bw.write(i + "\t" + avg + "\n"); bw.flush(); } bw.close(); }
Example 16
Source File: LocationQueryEmulationTest.java From epcis with Apache License 2.0 | 4 votes |
public void test() throws IOException, InterruptedException, ParserConfigurationException, SAXException, ParseException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("epcis"); db.getCollection("EventData").drop(); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("edges").createIndex(new BsonDocument("_outV", new BsonInt32(1)).append("_t", new BsonInt32(1)) .append("_inV", new BsonInt32(1))); client.close(); for (int i = 0; i < transferCount; i++) { // Insert Event String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument schemaVersion=\"1.2\"\n" + " creationDate=\"2013-06-04T14:59:02.099+02:00\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\"\n" + " xmlns:example=\"http://ns.example.com/epcis\">\n" + " <EPCISBody>\n" + " <EventList>"; String bottom = "</EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String cTime = sdf.format(new Date()); String body = ""; Thread.sleep(1000); cTime = sdf.format(new Date()); body += "<ObjectEvent>\n" + " <eventTime>" + cTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <epcList>\n" + " <epc>urn:epc:id:sgtin:0000001.000001.0</epc>\n" + " </epcList>\n" + " <action>OBSERVE</action>\n" + " <bizStep>urn:epcglobal:cbv:bizstep:receiving</bizStep>\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:0000001.00001." + i + "</id>\n" + " </bizLocation>\n" + "</ObjectEvent>"; EventCapture cap = new EventCapture(); cap.capture(top + body + bottom); Thread.sleep(1000); double avg = doTransformationQuery(); System.out.println(i + "\t" + avg); bw.write(i + "\t" + avg + "\n"); bw.flush(); } bw.close(); }
Example 17
Source File: TransformationQueryTest.java From epcis with Apache License 2.0 | 4 votes |
public void test() throws IOException, InterruptedException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("epcis"); db.getCollection("EventData").drop(); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("tEdgeEvents").drop(); db.getCollection("tVertexEvents").drop(); MongoDatabase db2 = client.getDatabase("epcis-data"); db2.getCollection("vertices").drop(); client.close(); for (int i = 0; i < transferCount; i++) { // Insert Event String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument schemaVersion=\"1.2\"\n" + " creationDate=\"2013-06-04T14:59:02.099+02:00\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\"\n" + " xmlns:example=\"http://ns.example.com/epcis\">\n" + " <EPCISBody>\n" + " <EventList>"; String bottom = "</EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String cTime = sdf.format(new Date()); String body = ""; cTime = sdf.format(new Date()); body += "<extension>\n" + " <TransformationEvent>\n" + " <eventTime>" + cTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <inputEPCList>\n" + " <epc>urn:epc:id:sgtin:0000001.000001." + i + "</epc>\n" + " </inputEPCList>\n" + " <outputEPCList>\n" + " <epc>urn:epc:id:sgtin:0000001.000001." + (2 * i + 1) + "</epc>\n" + " <epc>urn:epc:id:sgtin:0000001.000001." + (2 * i + 2) + "</epc>\n" + " </outputEPCList>\n" + " </TransformationEvent>\n" + " </extension>"; EventCapture cap = new EventCapture(); cap.capture(top + body + bottom); Thread.sleep(2000); int length = doTransformationQuery(); System.out.println(i + "\t" + length); bw.write(i + "\t" + length + "\n"); bw.flush(); } bw.close(); }
Example 18
Source File: LocationQueryTest.java From epcis with Apache License 2.0 | 4 votes |
public void test() throws IOException, InterruptedException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("epcis"); db.getCollection("EventData").drop(); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("edges").createIndex(new BsonDocument("_outV", new BsonInt32(1)).append("_t", new BsonInt32(1)) .append("_inV", new BsonInt32(1))); client.close(); for (int i = 0; i < transferCount; i++) { // Insert Event String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument schemaVersion=\"1.2\"\n" + " creationDate=\"2013-06-04T14:59:02.099+02:00\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\"\n" + " xmlns:example=\"http://ns.example.com/epcis\">\n" + " <EPCISBody>\n" + " <EventList>"; String bottom = "</EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String cTime = sdf.format(new Date()); String body = ""; Thread.sleep(1000); cTime = sdf.format(new Date()); body += "<ObjectEvent>\n" + " <eventTime>" + cTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <epcList>\n" + " <epc>urn:epc:id:sgtin:0000001.000001.0</epc>\n" + " </epcList>\n" + " <action>OBSERVE</action>\n" + " <bizStep>urn:epcglobal:cbv:bizstep:receiving</bizStep>\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:0000001.00001." + i + "</id>\n" + " </bizLocation>\n" + "</ObjectEvent>"; EventCapture cap = new EventCapture(); cap.capture(top + body + bottom); Thread.sleep(1000); double avg = doTransformationQuery(); System.out.println(i + "\t" + avg); bw.write(i + "\t" + avg + "\n"); bw.flush(); } bw.close(); }
Example 19
Source File: TagRepository.java From tutorials with MIT License | 4 votes |
/** * Instantiates a new TagRepository by opening the DB connection. */ public TagRepository() { mongoClient = new MongoClient("localhost", 27018); MongoDatabase database = mongoClient.getDatabase("blog"); collection = database.getCollection("posts"); }
Example 20
Source File: MongoDirectory.java From lumongo with Apache License 2.0 | 2 votes |
/** * Removes an index from a database * @param mongo * @param dbname * @param indexName */ public static void dropIndex(MongoClient mongo, String dbname, String indexName) { MongoDatabase db = mongo.getDatabase(dbname); db.getCollection(indexName + MongoDirectory.BLOCKS_SUFFIX).drop(); db.getCollection(indexName + MongoDirectory.FILES_SUFFIX).drop(); }