List of usage examples for com.mongodb MongoClient MongoClient
public MongoClient(final MongoClientURI uri, final MongoDriverInformation mongoDriverInformation)
From source file:br.bireme.web.AuthenticationServlet.java
License:Open Source License
@Override public void init() { try {//w ww . j a v a2 s .c om final ServletContext context = getServletContext(); final String host = context.getInitParameter("host"); final int port = Integer.parseInt(context.getInitParameter("port")); final String user = context.getInitParameter("username"); final String password = context.getInitParameter("password"); final MongoClient mongoClient = new MongoClient(host, port); final DB db = mongoClient.getDB(SOCIAL_CHECK_DB); if (!user.trim().isEmpty()) { final boolean auth = db.authenticate(user, password.toCharArray()); if (!auth) { throw new IllegalArgumentException("invalid user/password"); } } final DBCollection coll = db.getCollection(BROKEN_LINKS_COL); final DBCollection hcoll = db.getCollection(HISTORY_COL); final Set<String> databases = MongoOperations.getDatabases(coll); context.setAttribute("userEmail", user.trim()); context.setAttribute("collection", coll); context.setAttribute("historycoll", hcoll); context.setAttribute("readOnlyMode", false); context.setAttribute("databases", databases); } catch (Exception ex) { Logger.getLogger(AuthenticationServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:br.com.locadora.util.MongoConnection.java
public MongoDatabase getDB() { if (mongoClient == null) { mongoClient = new MongoClient(HOST, PORT); db = mongoClient.getDatabase(DB_NAME); System.out.println("Mongo instance equals :> " + mongoInstance++); }/*from w ww. j a va2 s . com*/ return db; }
From source file:br.com.teste.mongo.MongoTeste.java
public DB connect() { DB db = null;/* w w w . j av a2 s . co m*/ try { MongoClient mongoClient = new MongoClient("localhost", 27017); db = mongoClient.getDB("testeTesseract"); } catch (UnknownHostException ex) { Logger.getLogger(MongoTeste.class.getName()).log(Level.SEVERE, null, ex); } return db; }
From source file:br.edu.ifpb.bdnc.conexao.ConectionMongoDb.java
public static MongoCollection<Document> openConnection() { mongoClient = new MongoClient("localhost", 27017); MongoDatabase database = mongoClient.getDatabase("databasemongo"); MongoCollection<Document> collection = database.getCollection("post"); return collection; }
From source file:br.edu.ifpb.bdnc.gory.dao.bd.MongoDAO.java
public MongoDAO() { mongoClient = new MongoClient("localhost", 27017); database = mongoClient.getDatabase("gory"); collection = database.getCollection("Pagina"); }
From source file:br.edu.ifpb.bdnc.mongodb.Connectmongo.java
public MongoDatabase Connectmongo() { mongoClient = new MongoClient("localhost", 27017); database = mongoClient.getDatabase("ativBDNC"); return database; }
From source file:br.edu.utfpr.webapp.dao.MongoUtil.java
public static MongoClient getMongo() { if (mongo == null) { mongo = new MongoClient(host, port); logger.debug("New Mongo created with [" + host + "] and [" + port + "]"); }/* w w w. j a v a 2 s. com*/ return mongo; }
From source file:br.inpe.lac.projetoalunoseorientadoresinpe2016.controller.Controller.java
public String getAllPersons() throws Exception { MongoClientOptions options = MongoClientOptions.builder().connectionsPerHost(100).build(); MongoClient mongoClient = new MongoClient(new ServerAddress(), options); MongoDatabase my_db = mongoClient.getDatabase("alunos_e_orientadores_inpe"); MongoCollection<Document> pessoas = my_db.getCollection("pessoas"); List<Document> list = pessoas.find().into(new ArrayList<Document>()); return new Gson().toJson(list); }
From source file:br.inpe.lac.projetoalunoseorientadoresinpe2016.mongo.Mongo.java
public Mongo() { options = MongoClientOptions.builder().connectionsPerHost(100).build(); mongoClient = new MongoClient(new ServerAddress(), options);//MongoClient mongoClient = new MongoClient(new MongoClientURI("mongod://localhost:27017")); my_db = mongoClient.getDatabase("alunos_orientadores_inpe"); alunos = my_db.getCollection("alunos"); orientadores = my_db.getCollection("orientadores"); }
From source file:br.rdu.ifpb.mongo.repositorio.PessoaRepositoriMongo.java
private DB getConnection() { try {/*from w w w . j a v a 2 s . c om*/ mongo = new MongoClient(host, port); } catch (UnknownHostException ex) { Logger.getLogger(PessoaRepositoriMongo.class.getName()).log(Level.SEVERE, null, ex); } return mongo.getDB(BD); }