List of usage examples for com.mongodb.client MongoCollection find
FindIterable<TDocument> find(ClientSession clientSession);
From source file:MenuIS.java
public static void getIS() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("derivProb", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results.limit(1)) { List<String> conv = (List<String>) doc.get("initialState"); {// w w w .ja va2 s.c o m for (String s : conv) ISTextArea.append(s + "\n"); } } }
From source file:Register.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: MongoClient client = new MongoClient("localhost", 27017); MongoDatabase db = client.getDatabase("ExpenseManager"); MongoCollection<Document> reg = db.getCollection("Registration"); String unm = jTextField2.getText(); BasicDBObject query = new BasicDBObject("unm", unm); String pass = String.valueOf(jPasswordField1.getPassword()); String c_pass = String.valueOf(jPasswordField2.getPassword()); if (unm.length() == 0) { JOptionPane.showMessageDialog(null, "User Name is empty"); this.setVisible(true); }/*from w w w .j a va 2 s. c o m*/ else if (reg.find(query).iterator().hasNext()) { JOptionPane.showMessageDialog(null, "User Name already exist"); this.setVisible(true); } else if (jPasswordField1.getPassword().length == 0 || jPasswordField2.getPassword().length == 0) { JOptionPane.showMessageDialog(null, "Password Field Can not be empty"); this.setVisible(true); } else if (!pass.equals(c_pass)) { JOptionPane.showMessageDialog(null, "Passwords do not match. Please Re-enter the password"); this.setVisible(true); } else { String name = jTextField1.getText(); Document ins = new Document("name", name).append("unm", unm).append("pass", pass); reg.insertOne(ins); System.out.println("Document is inserted into MongoDb"); System.out.println(pass); db.createCollection(unm); this.dispose(); login lgn = new login(); lgn.setVisible(true); } }
From source file:anuncius.singleton.AnunciusDAO.java
public List<Document> search(String query) { Document result = new Document(); result.put("deleted", false); MongoCollection collection = this.mongo.getCollection(ADVERTISEMENT_COLLECTION_NAME); BasicDBObject document = new BasicDBObject("$text", new BasicDBObject("$search", query)); Collection data = collection.find(document).into(new ArrayList<>()); return new ArrayList(data); }
From source file:anuncius.singleton.MongoHandler.java
public Document read(int id, String collectionName) { MongoCollection<Document> collection = mainDatabase.getCollection(collectionName); Document document = new Document(); document.put("_id", id); document.put("deleted", false); ArrayList<Document> result = collection.find(document).limit(1).into(new ArrayList<>()); if (result != null && result.size() == 1) { return result.get(0); }/* ww w. j a v a2 s .c o m*/ return null; }
From source file:anuncius.singleton.MongoHandler.java
public Document read(Document document, String collectionName) { MongoCollection<Document> collection = mainDatabase.getCollection(collectionName); document.put("deleted", false); ArrayList<Document> result = collection.find(document).limit(1).into(new ArrayList<>()); if (result != null && result.size() == 1) { return result.get(0); }/* w w w . j av a 2s. c o m*/ return null; }
From source file:anuncius.singleton.MongoHandler.java
public List<Document> getList(String collectionName, int limit, int sort, Document result, String sortParam) { MongoCollection<Document> collection = mainDatabase.getCollection(collectionName); if (collection != null) { FindIterable<Document> iterable; if (result == null) { result = new Document(); }// w w w. j a va2s. c o m iterable = collection.find(result); if (limit > 0) { iterable = iterable.limit(limit); } if (sortParam != null) { iterable = iterable.sort(new BasicDBObject(sortParam, sort)); } return iterable.into(new ArrayList<>()); } return new ArrayList<>(); }
From source file:ARS.DBManager.java
public boolean findUserByName(String name) { User uObj;/*from www .j a va 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("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 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 w w w .jav a 2s.c om } if (counter == 1) { return true; } else { return false; } }
From source file:ARS.DBManager.java
public boolean findNullForGender() { User uObj;//from ww w . j av 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 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("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; } }