List of usage examples for com.mongodb MongoClient MongoClient
public MongoClient(final MongoClientURI uri, final MongoDriverInformation mongoDriverInformation)
From source file:ARS.DBManager.java
public void insertUser(User uObj) { try {/* w w w . jav a2 s .co m*/ MongoClient mongoClient = new MongoClient("localhost", 27017); //Connecting MongoDatabase db = mongoClient.getDatabase("ars"); System.out.println("Connecting to the db..."); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert System.out.println(collection); Document inputObj = new Document(); // inputObj.put("_id", 1123); inputObj.put("first-name", uObj.getFirstName()); inputObj.put("last-name", uObj.getLastName()); inputObj.put("gender", uObj.getGender()); inputObj.put("nationality", uObj.getNation()); inputObj.put("phone-number", uObj.getPhoneNumber()); inputObj.put("email", uObj.geteMail()); inputObj.put("password", uObj.getPassword()); inputObj.put("user-type", "customer"); collection.insertOne(inputObj); } catch (Exception e) { e.printStackTrace(); } }
From source file:ARS.DBManager.java
public boolean findUserByName(String name) { User uObj;/*from ww w . j a v a 2s. co 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("first-name", name); 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 deleteUser(String firstName) { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("first-name", firstName); collection.deleteOne(searchQuery);// ww w . j a va 2 s.c o m if (findUserByName(firstName) == false) { return true; } else return false; }
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 www . j a v a2 s . com } 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 www. jav a2 s . co m } if (counter == 1) { return true; } else { return false; } }
From source file:ARS.DBManager.java
public boolean findNullForGender() { User uObj;/* ww w . j av a 2s . co 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 w w. j a v a2 s. c om 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 . j ava2s . com*/ 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 ww w .ja va2s .co 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()); }/* w ww . j a va2 s .c o m*/ return flightList; }