List of usage examples for com.mongodb Mongo Mongo
Mongo(final MongoClientURI mongoURI)
From source file:AdminServer.ServiceS.java
private void DBConnect() { try {/*w w w. j a v a 2 s .c om*/ mongo = new Mongo(new ServerAddress("", 27017)); db = mongo.getDB("bank"); admins = db.getCollection("admins"); users = db.getCollection("users"); clients = db.getCollection("clients"); records = db.getCollection("records"); } catch (UnknownHostException e) { e.printStackTrace(); } catch (MongoException e) { e.printStackTrace(); } }
From source file:at.tuwien.aic.Main.java
private static void classifyTopic() { String topic = getNonEmptyString("Enter a topic you want to query"); Mongo mongo;/*from w ww. j av a 2s . c o m*/ DB db = null; try { mongo = new Mongo(_prop.getProperty("db_host")); db = mongo.getDB(_prop.getProperty("db_name")); } catch (UnknownHostException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); return; } Classifier c = ClassifyTweet.loadModel("resources/classifier.model"); TweetScorer scorer = new TweetScorer(); DBCollection tweetCollection = db.getCollection("tweets"); Pattern pattern = Pattern.compile("^.+" + topic + ".+$"); DBObject query = QueryBuilder.start("text").regex(pattern).get(); DBCursor resultSet = tweetCollection.find(query); int count = 0; double value = 0; double tweetClassifiedScore = 0; double tweetPosUserScore = 0; double tweetNegUserScore = 0; while (resultSet.hasNext()) { try { DBObject obj = resultSet.next(); String tweetText = (String) obj.get("text"); tweetClassifiedScore += ClassifyTweet.classifyTweet(c, tweetText); double score = scorer.scoreTweet(obj); if (tweetClassifiedScore > 0) { tweetPosUserScore += score; } else { tweetNegUserScore += score; } ++count; } catch (NumberFormatException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } // Normalizing between 0 an 1 value = tweetPosUserScore / (tweetPosUserScore + tweetNegUserScore); System.out.println("This topic has a sentiment value of: " + value); }
From source file:be.solidx.hot.spring.config.MongoConfig.java
License:Open Source License
@Bean public Map<DataSource, Mongo> mongoDBs() { Map<DataSource, Mongo> mongos = new LinkedHashMap<HotConfig.DataSource, Mongo>(); for (DataSource dataSource : hotConfig.getDataSources()) { if (dataSource.getEngine() == DBEngine.MONGODB) { try { mongos.put(dataSource, new Mongo(dataSource.getHostname())); } catch (Exception e) { LOG.error("", e); }/*from www . ja v a 2s .co m*/ } } return mongos; }
From source file:biz.bidi.archivee.commons.dao.mongodb.ArchiveeMongodbDAO.java
License:Open Source License
public ArchiveeMongodbDAO() { try {/*from w w w . j a va 2 s. c o m*/ loadProperties(ArchiveeMongodbDAO.class.getSimpleName() + "."); Mongo mongo = new Mongo(host); /* * Entities should added here */ Morphia morphia = new Morphia(); morphia.map(Pattern.class); morphia.map(LogQueue.class); morphia.map(Context.class); morphia.map(ContextIndex.class); morphia.map(ContextQueue.class); morphia.map(MasterIndex.class); morphia.map(Dictionary.class); morphia.map(DictionaryQueue.class); morphia.map(Template.class); morphia.map(TemplateDictionary.class); morphia.map(App.class); morphia.map(MasterIndex.class); morphia.map(Locker.class); ds = morphia.createDatastore(mongo, database); ds.ensureIndexes(); ds.ensureCaps(); } catch (ArchiveeException e) { ArchiveeException.error(e, "Unable to load MongoDB properties succesfully", this); } catch (Exception e) { ArchiveeException.error(e, "Unable to connect to MongoDB database", this); } }
From source file:cascading.mongodb.MongoWrapper.java
License:Apache License
static private Mongo makeInstance(String hostname, int port, String database) throws UnknownHostException { return new Mongo(new DBAddress(hostname, port, database)); }
From source file:cc.acs.mongofs.gridfs.CLI.java
License:Apache License
private static Mongo getMongo() throws Exception { if (_mongo == null) _mongo = new Mongo(host); return _mongo; }
From source file:ch.qos.logback.contrib.mongodb.DefaultMongoFactory.java
License:Open Source License
/** * Creates a {@link com.mongodb.Mongo} instance * @param uri - database URI//from w w w . j a v a 2s . c o m * @return the Mongo instance * @throws UnknownHostException */ @Override public Mongo createMongo(MongoURI uri) throws UnknownHostException { return new Mongo(uri); }
From source file:Collector.MongoDbConnector.java
public static void initMongoDB() throws MongoException { try {// ww w . ja va 2 s.c om System.out.println("Connecting to Mongo Db.."); Mongo mongo; mongo = new Mongo("127.0.0.1"); db = mongo.getDB("tweetDB"); } catch (UnknownHostException ex) { System.out.println("MongoDb Connection Erorr :" + ex.getMessage()); } }
From source file:com.aguin.stock.recommender.MongoStockConnection.java
License:Apache License
public static DB instance() { if (dbConnect == null) { try {//w ww . j av a2 s .c o m dbConnect = new Mongo(dbURI); } catch (UnknownHostException e) { e.printStackTrace(); } db = dbConnect.getDB(dbStock); dbCol = db.getCollection(dbCollectionName); } return db; }
From source file:com.aguin.stock.recommender.MongoStockConnection.java
License:Apache License
public static DBCollection collection() { if (dbConnect == null) { try {/*from ww w . j av a 2 s.co m*/ dbConnect = new Mongo(dbURI); } catch (UnknownHostException e) { e.printStackTrace(); } db = dbConnect.getDB(dbStock); dbCol = db.getCollection(dbCollectionName); } return dbCol; }