List of usage examples for com.mongodb MongoClient MongoClient
public MongoClient(final MongoClientURI uri)
From source file:amazonwebcrawler.Mongo.java
private DBCollection queryDb(String[] args) { try {//from w w w . j ava 2s . c om /**** Connect to MongoDB ****/ // Since 2.10.0, uses MongoClient MongoClientURI uri = new MongoClientURI( "mongodb://heroku_73s67dx7:2d6hshk9a78f2dlfkachg486t7@ds011399.mlab.com:11399/heroku_73s67dx7"); MongoClient mongo = new MongoClient(uri); /**** Get database ****/ // if database doesn't exists, MongoDB will create it for you DB db = mongo.getDB("heroku_73s67dx7"); /**** Get collection / table from 'testdb' ****/ // if collection doesn't exists, MongoDB will create it for you DBCollection table = db.getCollection("products"); return table; } catch (MongoException e) { e.printStackTrace(); } return null; }
From source file:at.grahsl.kafka.connect.mongodb.end2end.MinimumViableIT.java
License:Apache License
@BeforeAll public static void setup() throws IOException { CONTAINER_ENV.start();/*from w w w .jav a 2s. com*/ MONGODB_CLIENT_URI = new MongoClientURI("mongodb://" + MONGODB + ":" + MONGODB_PORT + "/kafkaconnect"); MONGO_CLIENT = new MongoClient(MONGODB_CLIENT_URI); MONGO_DATABASE = MONGO_CLIENT.getDatabase(MONGODB_CLIENT_URI.getDatabase()); Properties props = new Properties(); props.put("bootstrap.servers", KAFKA_BROKER + ":" + KAFKA_BROKER_PORT); props.put("key.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer"); props.put("value.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer"); props.put("schema.registry.url", "http://" + SCHEMA_REGISTRY + ":" + SCHEMA_REGISTRY_PORT); PRODUCER = new KafkaProducer<>(props); String config = new String(Files.readAllBytes(Paths.get(SINK_CONNECTOR_CONFIG))); deferExecutionToWaitForDataPropagation(Duration.ofMinutes(2), "wait some time so that all container processes become available"); registerMongoDBSinkConnector(config); }
From source file:at.rocworks.oa4j.logger.dbs.NoSQLMongoDB.java
private void initStorage(String url, String db) { JDebug.out.info("mongodb init storage..."); MongoClientURI uri = new MongoClientURI(url); client = new MongoClient(uri); database = client.getDatabase(db);//from w ww .j av a 2 s . c o m evcoll = database.getCollection("events"); }
From source file:bank_server.Bank_Server.java
public static void main(String[] args) throws IOException { int PORT = 0; int POOL_SIZE = 0; int MAX_POOL_SIZE = 0; int KEEP_ALIVE = 0; // <editor-fold defaultstate="collapsed" desc="Init Properties"> /*//from ww w. j ava 2 s . c o m try { Properties prop = new Properties(); FileOutputStream fos = new FileOutputStream("Bank_Serveur.properties"); prop.setProperty("port", "7300"); prop.setProperty("poolSize", "3"); prop.setProperty("maxPoolSize", "5"); prop.setProperty("keepAlive", "10"); prop.store(fos, null); } catch(Exception ex){} */ // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Load Properties"> try { Properties prop = new Properties(); FileInputStream fis = new FileInputStream("Bank_Serveur.properties"); prop.load(fis); PORT = Integer.parseInt(prop.getProperty("port", "7300")); POOL_SIZE = Integer.parseInt(prop.getProperty("poosSize", "3")); MAX_POOL_SIZE = Integer.parseInt(prop.getProperty("maxPoolSize", "5")); KEEP_ALIVE = Integer.parseInt(prop.getProperty("keepAlive", "10")); fis.close(); } catch (IOException ex) { Logger.getLogger(Bank_Server.class.getName()).log(Level.SEVERE, null, ex); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Connexion DB"> DBCollection collection = null; try { MongoClient mongoClient = new MongoClient("10.43.14.40"); DB db = mongoClient.getDB("java"); collection = db.getCollection("transactions"); } catch (UnknownHostException ex) { Logger.getLogger(Bank_Server.class.getName()).log(Level.SEVERE, null, ex); } // </editor-fold> Main2 thread = new Main2(collection); thread.start(); Pool threads = new Pool(POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE); SSLServerSocket sSock = SSL.getSSLServerSocket(PORT); while (true) { SSLSocket cSock = (SSLSocket) sSock.accept(); threads.pool.execute(new Task(cSock, collection)); } }
From source file:be.nille.blog.web.BeanConfig.java
@Bean public MongoDatabase database() { final String url = System.getenv("MONGO_URL"); log.debug("MONGO URL:" + url); try {//from www . j a v a2 s. c o m MongoClient client = new MongoClient(new MongoClientURI(url)); return client.getDatabase("openid-connect"); } catch (RuntimeException ex) { log.error(ex.getMessage()); throw new RuntimeException(String.format("Could not connect to Mongo Database with URL %s", url)); } }
From source file:br.bireme.scl.MongoOperations.java
License:Open Source License
public static void main(final String[] args) throws UnknownHostException, IOException { final MongoClient mongoClient = new MongoClient("ts01vm.bireme.br"); final DB db = mongoClient.getDB(SOCIAL_CHECK_DB); final DBCollection coll = db.getCollection(BROKEN_LINKS_COL); final DBCollection hcoll = db.getCollection(HISTORY_COL); final Set<String> centers = getCenters(coll); for (String center : centers) { System.out.println(center); }/* w w w . j a va 2 s .c om*/ System.out.println(); /*final List<IdUrl> ius = getCenterUrls(coll, "PE1.1"); for (IdUrl iu : ius) { System.out.println("1) " + iu.id + " " + iu.url); } final Set<IdUrl> rel = fixRelatedUrls(coll, hcoll, "Heitor", "PE1.1", //"xhttp://new.paho.org/bireme/index.php?Itemid=43&lang=pt", //"http://new.paho.org/bireme/index.php?Itemid=43&lang=pt"); //"http://new.paho.org/bireme/indexx.php?Itemid=43&lang=pt", //"http://new.paho.org/bireme/index.php?Itemid=43&lang=pt"); "http://new.paho.org/bireme/indexx.php?Itemid=43&lang=xpt", "http://new.paho.org/bireme/index.php?Itemid=43&lang=pt"); //"http://new.paho.org/bireme/index.php?Itemid=43&lang=xpt", //"http://new.paho.org/bireme/index.php?Itemid=43&lang=pt"); for (IdUrl iu : rel) { System.out.println("2) " + iu.id + " " + iu.url); }*/ }
From source file:br.com.ifspsaocarlos.gastock.library.Mongodb.java
public Mongodb() { try {/* w w w . ja va 2s . co m*/ mongoClient = new MongoClient( new MongoClientURI("mongodb://ifspsaocarlos:147258369@52.67.101.151/gastock")); db = mongoClient.getDB("gastock"); } catch (Exception e) { System.out.println("Ocorreu um erro na conexo com o banco de dados"); } }
From source file:br.com.mmsr.api.util.SpringMongoConfig.java
@Override @Bean public Mongo mongo() throws Exception { return new MongoClient("localhost"); }
From source file:br.com.mobclip.MongoConfiguration.java
License:Apache License
@Override @Bean public Mongo mongo() throws Exception { return new MongoClient("127.0.0.1"); }
From source file:br.com.rbezerra.RegisterQueue.DAO.Session.java
public Session(MongoClientURI uri) { try {//from w ww . ja v a 2s. c om client = new MongoClient(uri); db = client.getDB("registerqueue"); } catch (UnknownHostException e) { throw new IllegalArgumentException(uri.getURI()); } catch (MongoException e) { throw new IllegalArgumentException(uri.getURI()); } }