List of usage examples for com.mongodb.client MongoDatabase getCollection
MongoCollection<Document> getCollection(String collectionName);
From source file:com.cognitive.cds.invocation.mongo.WorkProductDao.java
License:Apache License
public UpdateResult updateWorkProductAssignment(WorkProductAssignment wpa) throws JsonProcessingException { mongoDbDao.setDatabase("work"); MongoClient mongo = mongoDbDao.getMongoClient(); MongoDatabase db = mongo.getDatabase("work"); MongoCollection<Document> collection = db.getCollection("work"); WorkProductWrapper wpw;/* ww w . j av a 2 s . c om*/ Document filter = new Document(); if (wpa.getUser() == null) return null; else filter.put("_id", new ObjectId(wpa.getWorkProductId())); Document obj = collection.find(filter).first(); UpdateResult result = null; if (obj != null) { try { String json = obj.toJson(); wpw = (WorkProductWrapper) JsonUtils.getMapper().readValue(json, WorkProductWrapper.class); Iterator<WorkProductAssignment> iterator = wpw.getAssignments().iterator(); // remove if there is an existing work product assignment with the same user id and work product id. while (iterator.hasNext()) { WorkProductAssignment workProductAssignment = (WorkProductAssignment) iterator.next(); if (workProductAssignment.getUser().getId().equalsIgnoreCase(wpa.getUser().getId()) && workProductAssignment.getWorkProductId().equalsIgnoreCase(wpa.getWorkProductId())) { iterator.remove(); } } // add the new work product assignment wpw.getAssignments().add(wpa); String objectJson = JsonUtils.getMapper().writeValueAsString(wpw); Document doc = Document.parse(objectJson); doc.put("_id", new ObjectId(wpa.getWorkProductId())); result = mongoDbDao.getCollection("work").replaceOne(filter, doc); } catch (IOException e) { logger.error("========> Deserialize: " + e.toString()); } } return result; }
From source file:com.cognitive.cds.invocation.mongo.WorkProductSubscriptionDao.java
License:Apache License
public String deleteWorkProductSubscription(WorkProductSubscription wps) throws JsonProcessingException { mongoDbDao.setDatabase("work"); MongoClient mongo = mongoDbDao.getMongoClient(); MongoDatabase db = mongo.getDatabase("work"); MongoCollection<Document> collection = db.getCollection("subscriptions"); BasicDBObject query = new BasicDBObject(); query.append("user", wps.getUser()); DeleteResult result = collection.deleteOne(query); return result.toString(); }
From source file:com.company.Action.java
License:Apache License
public void run() throws NotFound, ResponseException, InterruptedException { Way2SMS way2SMS = new Way2SMS(); way2SMS.Login(USERNAME, PASSWORD);/*from www .j a v a 2 s .c om*/ Set<User> hashset = new HashSet<>(); Set<String> numbers = new HashSet<>(); MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase database = mongoClient.getDatabase("Users"); MongoCollection<Document> collection = database.getCollection("credenzappusers"); // System.out.println(collection.count()); for (Document cur : collection.find()) { if (cur.get("Phone1") != null) { String value = String.valueOf(cur.get("Phone1")); if (value.length() == 10) { // System.out.println(value); if (!numbers.contains(value)) { numbers.add(value); hashset.add(new User(((String) cur.get("Name1")).split(" ")[0], value)); } } } if (cur.get("Phone2") != null) { String value = String.valueOf(cur.get("Phone2")); if (value.length() == 10) { // System.out.println(value); if (!numbers.contains(value)) { numbers.add(value); hashset.add(new User(((String) cur.get("Name2")).split(" ")[0], value)); } } } if (cur.get("Phone3") != null) { String value = String.valueOf(cur.get("Phone3")); if (value.length() == 10) { // System.out.println(value); if (!numbers.contains(value)) { numbers.add(value); hashset.add(new User(((String) cur.get("Name3")).split(" ")[0], value)); } } } // System.out.println("Phone2 is"+cur.get("Phone2")); } System.out.println(hashset.size()); collection = database.getCollection("credenzreceipt"); System.out.println(collection.count()); for (Document cur : collection.find()) { if (cur.get("Contact1") != null) { String value = String.valueOf(cur.get("Contact1")); if (value.length() == 10) { // System.out.println(value); if (!numbers.contains(value)) { numbers.add(value); hashset.add(new User(((String) cur.get("Name1")).split(" ")[0], value)); } } } if (cur.get("Contact2") != null) { String value = String.valueOf(cur.get("Contact2")); if (value.length() == 10) { // System.out.println(value); if (!numbers.contains(value)) { numbers.add(value); hashset.add(new User(((String) cur.get("Name2")).split(" ")[0], value)); } } } if (cur.get("Contact3") != null) { String value = String.valueOf(cur.get("Contact3")); if (value.length() == 10) { // System.out.println(value); if (!numbers.contains(value)) { numbers.add(value); try { hashset.add(new User(((String) cur.get("Name3")).split(" ")[0], value)); } catch (Exception e) { System.out.println("cought exception"); } } } } // System.out.println("Phone2 is"+cur.get("Phone2")); } collection = database.getCollection("droidfest_users"); // System.out.println(collection.count()); for (Document cur : collection.find()) { if (cur.get("phone_no") != null) { String value = String.valueOf(cur.get("phone_no")); if (value.length() == 10) { // System.out.println(value); if (!numbers.contains(value)) { numbers.add(value); hashset.add(new User(((String) cur.get("name")).split(" ")[0], value)); } } } } collection = database.getCollection("hingemeetusers"); // System.out.println(collection.count()); for (Document cur : collection.find()) { if (cur.get("Number") != null) { String value = String.valueOf(cur.get("Number")); if (value.length() == 10) { // System.out.println(value); if (!numbers.contains(value)) { numbers.add(value); hashset.add(new User(((String) cur.get("Name")).split(" ")[0], value)); } } } } System.out.println(hashset.size()); int i = 1; for (User user : hashset) { // System.out.print(user.getName()); // System.out.println(user.getPhone_no()); i++; if (i > 7) { way2SMS.SendSMS(user.getPhone_no(), "Hi " + user.getName() + "! This is how you can build your Campus Startup: http://bit.ly/28Pa8aC FREE first lesson: http://bit.ly/28POhxJ Only for you:)"); Thread.sleep(4000); } else { System.out.println("Interrupted for " + user.getPhone_no()); } System.out.println(i); } // List <User> number=new ArrayList<>(); // number.add(new User("lol","9819124829")); // number.add(new User("lol","8446499908")); // number.add(new User("lol","7709758284")); // number.add(new User("lol","8956613425")); // number.add(new User("lol","7276807536")); // for (int i=0;i<number.size();i++) { // way2SMS.SendSMS(number.get(i).getPhone_no(), "Hi "+number.get(i).getName()+"! This is how you can build your Campus Startup: http://bit.ly/28Pa8aC FREE first lesson: http://bit.ly/28POhxJ Only for you :)"); //args ; Phone no , Message // } }
From source file:com.creactiviti.piper.core.context.MongoContextRepository.java
License:Apache License
public MongoContextRepository(MongoDatabase aDatabase) { this.collection = aDatabase.getCollection("context"); }
From source file:com.creactiviti.piper.core.job.MongoJobRepository.java
License:Apache License
public MongoJobRepository(MongoDatabase aDatabase) { this.collection = aDatabase.getCollection("job").withDocumentClass(Job.class); }
From source file:com.creactiviti.piper.core.task.MongoCounterRepository.java
License:Apache License
public MongoCounterRepository(MongoDatabase aDatabase) { this.collection = aDatabase.getCollection("counter"); }
From source file:com.creactiviti.piper.core.task.MongoTaskExecutionRepository.java
License:Apache License
public MongoTaskExecutionRepository(MongoDatabase database) { this.collection = database.getCollection("job").withDocumentClass(TaskExecution.class); }
From source file:com.DA.assignment1.Query.Demonstrate.java
public void Answer() throws Exception { MongoClient mongoClient = new MongoClient(); MongoDatabase db = mongoClient.getDatabase("test"); MongoCollection<Document> tag = db.getCollection("tags"); MongoCollection<Document> movie = db.getCollection("movies"); MongoCollection<Document> rating = db.getCollection("ratings"); sum(movie);// ww w .j a v a 2s.c om //selectMovie(rating); Tag(tag); }
From source file:com.DA.assignment1.Query.Question1.java
public void Answer() { MongoClient mongoClient = new MongoClient(); MongoDatabase db = mongoClient.getDatabase("test"); FindIterable<Document> iterable1 = db.getCollection("movies").find(new Document("title", "Copycat (1995)")); iterable1.forEach(new Block<Document>() { @Override/*from w ww .j ava 2 s. co m*/ public void apply(final Document document) { System.out.println(document); //System.out.println("hah"); } }); }
From source file:com.DA.assignment1.Query.Question2.java
public void Answer() { MongoClient mongoClient = new MongoClient(); MongoDatabase db = mongoClient.getDatabase("test"); AggregateIterable<Document> iterable = db.getCollection("movies") .aggregate(asList(new Document("$unwind", "$generes"), new Document("$group", new Document("_id", "$generes").append("count", new Document("$sum", 1))), new Document("$sort", new Document("count", -1)))); iterable.forEach(new Block<Document>() { @Override// ww w. j a v a 2 s . co m public void apply(final Document document) { System.out.println(document.toJson()); } }); }