List of usage examples for com.mongodb.client MongoDatabase getCollection
MongoCollection<Document> getCollection(String collectionName);
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);// w ww .j a va 2 s . co 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 w w w. ja v a2 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++;/* www. j a v a2 s . c o m*/ } if (counter == 1) { return true; } else { return false; } }
From source file:ARS.DBManager.java
public boolean findNullForGender() { User uObj;//from www . j a v a 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;//from w w w . j av a 2s . com 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 {/*w w w . j a v a 2s .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 .jav 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()); }/* w w w. j a va2 s. com*/ return flightList; }
From source file:BankMongoDB.SessionsDAO.java
License:Apache License
public SessionsDAO(final MongoDatabase blogDatabase) { sessionsCollection = blogDatabase.getCollection("sessions"); }
From source file:bariopendatalab.db.DBAccess.java
public void createDB() { MongoDatabase database = client.getDatabase(DBNAME); database.createCollection(COLLNAME); MongoCollection<Document> collection = database.getCollection(COLLNAME); collection.createIndex(new BsonDocument("geometry", new BsonString("2dsphere"))); }