List of usage examples for com.mongodb MongoClient getDatabase
public MongoDatabase getDatabase(final String databaseName)
From source file:ARS.DBManager.java
public int findAllUsers() { int counter = 0; MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); MongoCursor cursor = collection.find().iterator(); while (cursor.hasNext()) { System.out.println(cursor.next()); counter++;/*from w w w. j a v a 2 s.c om*/ } return counter; }
From source file:ARS.DBManager.java
public boolean findUserByNumber(Long pNo) { int counter = 0; MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); query.put("phone-number", pNo); MongoCursor cursor = collection.find(query).iterator(); while (cursor.hasNext()) { System.out.println(cursor.next()); counter++;//from ww w. j a v a2 s . com } if (counter == 1) { return true; } else { return false; } }
From source file:ARS.DBManager.java
public boolean findNullForGender() { User uObj;/* www . j ava 2 s.c o m*/ int counter = 0; MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); query.put("gender", null); MongoCursor cursor = collection.find(query).iterator(); //Counter gives one if it's give the result while (cursor.hasNext()) { System.out.println(cursor.next()); counter++; } if (counter >= 1) { return true; } else { return false; } }
From source file:ARS.DBManager.java
public boolean findUserByEmail(String email, String password) { User uObj;// w ww. j av a2s. c o m int counter = 0; MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); query.put("email", email); query.put("password", password); MongoCursor cursor = collection.find(query).iterator(); //Counter gives one if it's give the result while (cursor.hasNext()) { System.out.println(cursor.next()); counter++; } if (counter == 1) { return true; } else { return false; } }
From source file:ARS.DBManager.java
public void insertFlight(Flight fObj) { try {/*from ww w . jav a2 s. c o m*/ MongoClient mongoClient = new MongoClient("localhost", 27017); //Connecting MongoDatabase db = mongoClient.getDatabase("ars"); System.out.println("Connecting to the db..."); MongoCollection collection = db.getCollection("flight"); //Choosing the collection to insert System.out.println(collection); Document flightObj = new Document(); flightObj.put("fNO", 1001); flightObj.put("departure", "Izmir"); flightObj.put("arrival", "Istanbul"); flightObj.put("date", "2017-05-08 12:00:00"); //TODO: Change this dummy date. collection.insertOne(flightObj); } catch (Exception e) { e.printStackTrace(); } }
From source file:ARS.DBManager.java
public void insertPlane(Plane pObj) { try {/*from w w w . j a v a 2 s .c o m*/ MongoClient mongoClient = new MongoClient("localhost", 27017); //Connecting MongoDatabase db = mongoClient.getDatabase("ars"); System.out.println("Connecting to the db..."); MongoCollection collection = db.getCollection("plane"); //Choosing the collection to insert System.out.println(collection); List<Object> seatDBList = new BasicDBList(); Document planeObj = new Document(); planeObj.put("pNo", 2); planeObj.put("flightNo", 2); planeObj.put("Type", "Airbus A380"); for (Seat seatList : pObj.getSeatVector()) //TODO: Change it { DBObject seatDBObject = new BasicDBObject(); seatDBObject.put("sNo", seatList.getSeatNumber()); seatDBObject.put("isEmpty", seatList.getIsEmpty()); seatDBObject.put("isEconomy", seatList.getIsEconomy()); seatDBList.add(seatDBObject); } planeObj.put("Seats", seatDBList); collection.insertOne(planeObj); } catch (Exception e) { e.printStackTrace(); } }
From source file:ARS.DBManager.java
public ArrayList findFlight(String departure, String arrival) { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); query.put("departure", departure); query.put("arrival", arrival); MongoCursor cursor = collection.find(query).iterator(); ArrayList<Flight> flightList = new ArrayList<>(); //Counter gives one if it's give the result while (cursor.hasNext()) { flightList.add((Flight) cursor.next()); }//from w ww . ja v a 2 s.c om return flightList; }
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 {/* ww w . ja va2 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.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.ufg.inf.es.saep.sandbox.persistencia.view.StartSaep.java
License:Creative Commons License
/** * Mtodo de inicializao do sistema./* www . j a v a 2 s .c o m*/ * * @param args the command line arguments */ public static void main(String[] args) { MongoClient cliente = new MongoClient(); MongoDatabase mongoDatabase = cliente.getDatabase("Saep"); InterfaceRadocDAO radocDAO = new BasicRadocDAO(mongoDatabase, "Radoc"); InterfaceTipoDAO tipoDAO = new BasicTipoDAO(mongoDatabase, "Tipo"); InterfaceResolucaoDAO resolucaoDAO = new BasicResolucaoDAO(mongoDatabase, "Resolucao"); InterfaceParecerDAO parecerDAO = new BasicParecerDAO(mongoDatabase, "Parecer"); mongoDatabase.drop(); System.out.println("Fim do programa"); }