List of usage examples for com.mongodb.client MongoCollection find
FindIterable<TDocument> find(ClientSession clientSession);
From source file:MenuDefCats.java
public static void getCats() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Types", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { List<String> conv = (List<String>) doc.get("Cats"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) CatsTextArea.append(s + "\n"); }/*from w ww. jav a 2s . c o m*/ }
From source file:MenuDefObj.java
public static void getObjects() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Types", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { List<String> conv = (List<String>) doc.get("Objects"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) ObjTextArea.append(s + "\n"); }/*from w w w. j a v a2 s . c om*/ }
From source file:MenuProb.java
public static void getProbability() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Probability", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { List<String> conv = (List<String>) doc.get("Probability"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) ProbTextArea.append(s + "\n"); }/*from w w w . j av a 2s .co m*/ }
From source file:WebCategorizer.java
public void getWebCategories(HashSet<String> urlSet, HashMap<String, String> websiteCategoryMap, MongoCollection<org.bson.Document> websiteCategoryCollection) { try {//from ww w . j av a 2s.c o m File file = new File(categoriesFile); JSONObject webCatList = new JSONObject(); if (file.exists() && file.length() != 0) { webCatList = loadCategories(); } else { webCatList = fetchCategories(); } for (String url : urlSet) { if (websiteCategoryMap.containsKey(url)) continue; org.bson.Document urlDoc = websiteCategoryCollection.find(eq("URLDomain", url)).first(); if (urlDoc == null) { String host = ""; String port = ""; if (url.indexOf(':') > -1) { String[] urlAddr = url.split(":"); host = urlAddr[0]; port = urlAddr[1]; } else { host = url; port = "80"; } StringBuilder remoteUrl = new StringBuilder("http://sp.cwfservice.net/1/R/"); remoteUrl.append(k9License); remoteUrl.append("/K9-00006/0/GET/HTTP/"); remoteUrl.append(host); remoteUrl.append("/"); remoteUrl.append(port); remoteUrl.append("///"); //Fetch Key for URL URL obj = new URL(remoteUrl.toString()); URLConnection connection = obj.openConnection(); Document doc = parseXML(connection.getInputStream()); NodeList descNodes = doc.getElementsByTagName("DomC"); if (descNodes.getLength() != 0) { String cat = (String) webCatList .get(breakString(descNodes.item(0).getTextContent().toLowerCase())); websiteCategoryMap.put(url, cat); websiteCategoryCollection.insertOne(new org.bson.Document("URLId", url.hashCode()) .append("URLDomain", url.toString()).append("URLCategory", cat)); } else { descNodes = doc.getElementsByTagName("DirC"); String cat = (String) webCatList .get(breakString(descNodes.item(0).getTextContent().toLowerCase())); websiteCategoryMap.put(url, cat); websiteCategoryCollection.insertOne(new org.bson.Document("URLId", url.hashCode()) .append("URLDomain", url.toString()).append("URLCategory", cat)); } } else { websiteCategoryMap.put(url, new JSONObject(urlDoc.toJson()).get("URLCategory").toString()); } } } catch (Exception ex) { System.out.println(ex.getClass().getName()); System.out.println("Not working"); } }
From source file:MenuDefAct.java
public static void getActions() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Types", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { List<String> conv = (List<String>) doc.get("Actions"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) ActTextArea.append(s + "\n"); }//from www . j a v a 2 s . co m }
From source file:MenuDefTyp.java
public static void getTypes() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Objects", new BasicDBObject("$gt", ".0001"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { // do something with each result List<String> conv = (List<String>) doc.get("Types"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) TypTextArea.append(s + "\n"); }// w w w. j ava 2 s . c om }
From source file:MenuDefPred.java
public static void getPreds() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Types", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { List<String> conv = (List<String>) doc.get("Predicates"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) PredTextArea.append(s + "\n"); }/* ww w .j av a2 s .c o m*/ }
From source file:Welcome.java
public void setListVal() { int i = 1;/*from ww w .j a va2 s .c om*/ MongoClient client = new MongoClient("localhost", 27017); MongoDatabase db = client.getDatabase("ExpenseManager"); MongoCollection<Document> reg = db.getCollection("Registration"); FindIterable<Document> find = reg.find(new Document("unm", unm)); Document doc = find.first(); DefaultListModel model; model = new DefaultListModel(); while (i <= 5) { if (!doc.containsKey("Account" + i)) { i++; } else { while (doc.containsKey("Account" + i)) { String s = (String) doc.get("Account" + i); s = s.concat(" "); s = s.concat((String) doc.get("Bank" + i)); s = s.concat(" "); s = s.concat((String) doc.get("Money" + i)); model.addElement(s); i++; } } } jList1.setModel(model); }
From source file:Welcome.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed /*MongoClient client = new MongoClient("localhost", 27017); DB db;/*w ww.j a v a 2 s. c o m*/ db = client.getDB("ExpenseManager"); DBCollection reg = (DBCollection) db.getCollection("Registration"); DBObject query = new BasicDBObject("unm", unm); DBObject update = new BasicDBObject(); update.put("$unset", new BasicDBObject("userId","")); */ int i = 1; int count = 1; MongoClient client = new MongoClient("localhost", 27017); MongoDatabase db = client.getDatabase("ExpenseManager"); MongoCollection<Document> reg = db.getCollection("Registration"); FindIterable<Document> find = reg.find(new Document("unm", unm)); DBObject query = new BasicDBObject("unm", unm); BasicDBObject update = new BasicDBObject(); Map<Integer, Integer> m = new HashMap<Integer, Integer>(); String val[] = new String[6]; val[0] = ""; Document doc = find.first(); while (i <= 5) { if (!doc.containsKey("Account" + i)) { i++; } else { while (doc.containsKey("Account" + i)) { m.put(count, i); val[count] = (String) (doc.get("Account" + i)); i++; count++; } } } JComboBox jcb = new JComboBox(val); jcb.setEditable(true); int msg = JOptionPane.showConfirmDialog(this, "Do You Really Want to remove Your Account?"); if (msg == 0) { JOptionPane.showMessageDialog(this, jcb, "Select Your Account to Remove", JOptionPane.QUESTION_MESSAGE); while (jcb.getSelectedItem().equals("")) { JOptionPane.showMessageDialog(this, "You Haven't chose any Account, Please Choose the Account"); JOptionPane.showMessageDialog(this, jcb, "Select Your Account to Remove", JOptionPane.QUESTION_MESSAGE); } int index = jcb.getSelectedIndex(); int value = m.get(index); String str1 = "Account" + value; String str2 = "Bank" + value; String str3 = "Money" + value; update.put("$unset", new BasicDBObject(str1, "").append(str2, "").append(str3, "")); UpdateResult updateOne = reg.updateOne(new Document("unm", unm), update); setListVal(); } // TODO add your handling code here: }
From source file:MenuDefCateg.java
public static void getCategories() { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("database"); MongoCollection<Document> elexirCollection = db.getCollection("test"); FindIterable<Document> results = elexirCollection .find(new BasicDBObject("Types", new BasicDBObject("$gt", "0"))); //FindIterable<Document> iter = elexirCollection.find(new BasicDBObject("derivProb", 2)); for (Document doc : results) { List<String> conv = (List<String>) doc.get("Category"); String[] convArr = new String[conv.size()]; convArr = conv.toArray(convArr); for (String s : convArr) CategTextArea.append(s + "\n"); }/*from w w w .jav a 2s . c o m*/ }