List of usage examples for com.mongodb MongoClientURI MongoClientURI
public MongoClientURI(final String uri)
From source file:com.zjy.mongo.util.MongoConfigUtil.java
License:Apache License
public static void setMongoURIString(final Configuration conf, final String key, final String value) { setMongoURI(conf, key, new MongoClientURI(value)); }
From source file:ConnectionManager.InitialConnection.java
public static MongoDatabase connector() { MongoClientURI connectionString = new MongoClientURI( "mongodb://ehsan:d11475290@aws-us-east-1-portal.13.dblayer.com:10372/admin"); MongoClient mongoClient = new MongoClient(connectionString); MongoDatabase database = mongoClient.getDatabase("iSantia"); return database; }
From source file:Dao.AccessDataNOSQL.java
License:Open Source License
/** * Metodo que se conecta a una coleccion de una base de datos no sql * @param baseDatos la base de datos a la que se conecta * @param coleccion coleccion de la base de datos * @return devuelve la coleccion de la base de datos a la que se conecta */// w w w . j a v a 2 s. com public MongoCollection<Document> consultaBD(String baseDatos, String coleccion) { String direccion = "mongodb://" + getUser() + ":" + getPassword() + "@" + getCadenaConexion(); //mongodb://bogdan:ar03pbo@ds033337.mongolab.com:33337/nosql MongoClientURI connectionString = new MongoClientURI(direccion); MongoClient mongoClient = new MongoClient(connectionString); MongoDatabase database = mongoClient.getDatabase(baseDatos);//nosql MongoCollection<Document> collec = database.getCollection(coleccion); return collec; }
From source file:de.adorsys.oauth.tokenstore.mongodb.MongoDbProvider.java
License:Apache License
@Produces @ApplicationScoped//from www . j a v a 2 s. c om public MongoDatabase producesMongoDatabase() { String mongoUri = System.getProperty("oauth.mongodb.uri", "mongodb://localhost:27017"); String mongoDb = System.getProperty("oauth.mongodb.database", "oauth"); try { MongoClientURI clientURI = new MongoClientURI(mongoUri); LOG.info("use {}, database '{}', collection '{}'", createLogUri(clientURI), mongoDb, MdbTokenStore.COLLECTION_NAME); MongoClient mongoClient = new MongoClient(clientURI); return mongoClient.getDatabase(mongoDb); } catch (Exception e) { throw new IllegalStateException(e); } }
From source file:DS.Model.java
public void MongoConnect() { MongoClientURI connString = new MongoClientURI(mongoURI); mClient = new MongoClient(connString); db = mClient.getDatabase(connString.getDatabase()); }
From source file:ec.edu.espe.persistence.PersistenceManager.java
public PersistenceManager() { MongoClientOptions mongoOptions = MongoClientOptions.builder().socketTimeout(60000).connectTimeout(60000) .build();/* www . j a va2 s. c om*/ try { //mongoClient = new MongoClient(new ServerAddress("ds038739.mlab.com:38739"), mongoOptions); String textUri = "mongodb://xmatch:xmatch@ds038739.mlab.com:38739/xmatch"; MongoClientURI uri = new MongoClientURI(textUri); mongoClient = new MongoClient(uri); } catch (Exception e) { throw new RuntimeException("Error", e); } mongoClient.setWriteConcern(WriteConcern.SAFE); mongoClient.setReadPreference(ReadPreference.primary()); morphia = new Morphia(); morphia.mapPackage(DB_PACKAGE, true); mds = morphia.createDatastore(mongoClient, DB_NAME); mds.ensureIndexes(); }
From source file:edu.eci.arsw.examples.MongoDBAccessExample.java
public static void main(String ap[]) throws UnknownHostException { MongoClientURI uri = new MongoClientURI("mongodb://test:test@ds031631.mongolab.com:31631/documents"); MongoClient client = new MongoClient(uri); DB db = client.getDB(uri.getDatabase()); DBCollection names = db.getCollection("commontypos"); DBCursor cur = names.find();//from ww w . j a v a2 s .co m while (cur.hasNext()) { DBObject doc = cur.next(); System.out.println(doc.get("words")); System.out.println(doc.get("pocibilidad")); } }
From source file:eu.project.ttc.models.occstore.MongoDBOccurrenceStore.java
License:Apache License
public MongoDBOccurrenceStore(String mongoDbUri, State state) { super();/* w w w. j av a 2 s . com*/ Preconditions.checkNotNull(mongoDbUri, "MongoDB dadabase's URI must not be null"); Preconditions.checkState(state != State.INDEXING, "Invalid occ store state for constructor. Only " + State.COLLECTING + " and " + State.INDEXED + " allowed"); this.mongoDBUri = getMongoDBUri(mongoDbUri); this.state = state; initThreadExecutor(); MongoClientURI connectionString = new MongoClientURI(mongoDbUri); this.mongoClient = new MongoClient(connectionString); MongoDatabase db = mongoClient.getDatabase(this.mongoDBUri.getDatabase()) .withWriteConcern(WriteConcern.ACKNOWLEDGED); db.runCommand(new org.bson.Document("profile", 1)); if (state == State.COLLECTING) db.drop(); this.termCollection = db.getCollection("terms"); this.occurrenceCollection = db.getCollection("occurrences"); this.documentUrlCollection = db.getCollection("documents"); resetBuffers(); }
From source file:eu.project.ttc.models.occstore.MongoDBOccurrenceStore.java
License:Apache License
private MongoClientURI getMongoDBUri(String mongoDbUri) { if (mongoDbUri.startsWith("mongodb://")) return new MongoClientURI(mongoDbUri); else/*from w ww .j a va 2s .c o m*/ // mongoDbUri is a db name return new MongoClientURI("mongodb://localhost:27017/" + mongoDbUri); }
From source file:eu.vital.vitalcep.cep.CEP.java
public Boolean CEPStart(CEPType type, DolceSpecification dolceSpecification, String mqin, String mqout, String confFile, String sources, JSONObject credentials) throws FileNotFoundException, IOException { ConfigReader configReader = ConfigReader.getInstance(); mongoURL = configReader.get(ConfigReader.MONGO_URL); mongoDB = configReader.get(ConfigReader.MONGO_DB); cp = new CepProcess(dolceSpecification.toString(), mqin, mqout, confFile); cp.startCEP();//w ww .j a v a2 s. c o m this.PID = cp.PID; CepContainer.putCepProc(cp); this.type = type.toString(); String T = type.toString(); if (cp.PID > 0) { this.fileName = cp.fileName; MongoClient mongo = new MongoClient(new MongoClientURI(mongoURL)); MongoDatabase db = mongo.getDatabase(mongoDB); try { Document doc = new Document(); doc.put("PID", PID); doc.put("mqin", mqin); doc.put("mqout", mqout); doc.put("dolceSpecification", dolceSpecification.toString()); doc.put("dolcefile", cp.cepFolder + "/" + cp.fileName); doc.put("cepType", T); doc.put("clientId", fileName); //doc.put("sensorId", id); doc.put("fileName", fileName); doc.put("cepFolder", cp.cepFolder); Date NOW = new Date(); switch (T) { case "DATA": doc.put("data", sources); break; case "QUERY": doc.put("querys", sources); break; case "CEPICO": case "ALERT": doc.put("lastRequest", getXSDDateTime(NOW)); BasicDBList sourcesCEPICO = (BasicDBList) JSON.parse(sources); doc.put("requests", sourcesCEPICO); doc.put("lastRequest", getXSDDateTime(NOW)); doc.put("username", credentials.getString("username")); doc.put("password", encrypt(credentials.getString("password"))); break; case "CONTINUOUS": BasicDBList sourcesB = (BasicDBList) JSON.parse(sources); BasicDBList propertiesB = (BasicDBList) JSON.parse(dolceSpecification.getEvents().toString()); doc.put("sources", sourcesB); doc.put("properties", propertiesB); doc.put("lastRequest", getXSDDateTime(NOW)); doc.put("username", credentials.getString("username")); doc.put("password", encrypt(credentials.getString("password"))); break; } doc.put("status", "OK"); db.getCollection("cepinstances").insertOne(doc); ObjectId idO = (ObjectId) doc.get("_id"); this.id = idO.toString(); if (id != null && !(T == "DATA" || T == "QUERY")) { Boolean insertIntoCollectorList = insertIntoCollectorList(doc, idO); if (!insertIntoCollectorList) { db.getCollection("cepinstances").updateOne(doc, new Document("$set", new Document("status", "no collector available"))); throw new ServerErrorException(500); } } } catch (JSONException | GeneralSecurityException | UnsupportedEncodingException | ServerErrorException ex) { String a = ""; } finally { if (db != null) db = null; if (mongo != null) { mongo.close(); mongo = null; } } } else { this.fileName = ""; return false; } return true; }