List of usage examples for com.mongodb.client MongoDatabase getCollection
MongoCollection<Document> getCollection(String collectionName);
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 ww w .j av a 2s . c o m*/ }
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"); {//from w ww . j a v a 2 s.co 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 ww.j a v a 2 s .c om*/ 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:adc.data.viewer.dao.ADCRecordDaoMongo.java
License:Open Source License
private MongoCollection<Document> getMongoDBDataBaseCollection() { MongoCollection<Document> collection = null; ConnectionBuilder connectionBuilder = ConnectionBuilderFactory.getConnectionBuilder(); if (connectionBuilder != null) { if (mongoClient == null) mongoClient = (MongoClient) connectionBuilder.getConnection(); if (mongoClient != null) { final MongoDatabase ADCDataViewer = mongoClient.getDatabase(dbName); collection = ADCDataViewer.getCollection(collectionName); }/*from w w w.j a v a 2s. c om*/ } return collection; }
From source file:alxpez.blog.SessionDAO.java
License:Apache License
public SessionDAO(final MongoDatabase blogDatabase) { sessionsCollection = blogDatabase.getCollection("sessions"); }
From source file:alxpez.blog.UserDAO.java
License:Apache License
public UserDAO(final MongoDatabase blogDatabase) { usersCollection = blogDatabase.getCollection("users"); }
From source file:analisissentimientos.SentimentAnnotated.java
public static void procesarDatasetAnotado() { File archivo = null;// w ww. jav a 2 s . c om FileReader fr = null; BufferedReader br = null; List<Document> jArray = new ArrayList<Document>(); try { archivo = new File( "D:\\Deisy universidad\\Big Data\\data\\01_debate08_sentiment_tweets\\debate08_sentiment_tweets_procesar.tsv"); fr = new FileReader(archivo); br = new BufferedReader(fr); // Lectura del fichero String linea; while ((linea = br.readLine()) != null) { String[] csvValues = linea.toString().split("\t"); Document json = new Document(); json.put("idTweet", csvValues[0]); json.put("date", csvValues[1]); json.put("content", csvValues[2]); json.put("authorName", csvValues[3]); json.put("authorNickname", csvValues[4]); int j = 1; String nameAttribute = ""; LinkedHashMap<Integer, Integer> ratings = new LinkedHashMap<Integer, Integer>(); for (int i = 5; i < csvValues.length; i++) { nameAttribute = "rating" + j; int rating = Integer.parseInt(csvValues[i]); ratings.put(rating, ratings.containsKey(rating) ? (ratings.get(rating) + 1) : 1); json.put(nameAttribute, csvValues[i]); j++; } int score = 1; int maxValueInMap = (Collections.max(ratings.values())); for (Map.Entry<Integer, Integer> entry : ratings.entrySet()) { if (entry.getValue() == maxValueInMap) { score = entry.getKey(); break; } } switch (score) { case 1: json.put("sentiment_score_annoted", "Negative"); break; case 2: json.put("sentiment_score_annoted", "Positive"); break; case 3: json.put("sentiment_score_annoted", "Mixed"); break; case 4: json.put("sentiment_score_annoted", "Other"); break; } //Mongo connection jArray.add(json); } MongoDatabase mongoDB = new MongoClient(DB_SERVER, DB_PORT).getDatabase(DB_NAME); MongoCollection mongoCollection = mongoDB.getCollection(COLLECTION_NAME); mongoCollection.insertMany(jArray); fr.close(); br.close(); ///tweet.id pub.date.GMT content author.name author.nickname rating.1 rating.2 rating.3 rating.4 rating.5 rating.6 rating.7 rating.8 } catch (Exception ex) { System.out.println("analisissentimientos.SentimentAnnotated.main() Error --->" + ex.toString()); } }
From source file:analisissentimientos.SentimentAnnotated.java
public static void consultarDatasetsAnotados() { MongoDatabase mongoDB = new MongoClient(DB_SERVER, DB_PORT).getDatabase(DB_NAME); MongoCollection mongoCollection = mongoDB.getCollection(COLLECTION_NAME); AggregateIterable<Document> result = mongoCollection.aggregate(Arrays.asList(new Document("$group", new Document("_id", "$sentiment_score_annoted").append("count", new Document("$sum", 1))))); for (Document doc : result) { System.out.println(doc);//from ww w. j a v a 2 s.co m } }
From source file:ARS.DBManager.java
public void insertUser(User uObj) { try {/*from w ww. j a v a2 s. com*/ 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 w ww . j av a 2 s .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; } }