Package com.mongodb

Examples of com.mongodb.MongoURI


  @Provides
  @Singleton
  public DB getDB() {

    // MongoDB Setup
    final MongoURI mongoUri = new MongoURI(configuration.getMongoUri());
    final DB db;
    try {
      db = mongoUri.connectDB();
    } catch (UnknownHostException e) {
      throw new IllegalArgumentException("Cannot connect to MongoDB",e);
    }

    // Authenticate
    if (mongoUri.getUsername() != null && mongoUri.getPassword() != null) {
      db.authenticate(mongoUri.getUsername(), mongoUri.getPassword());
    }

    return db;

  }
View Full Code Here


            public void run() {
                httpServer.stop();
            }
        });

        MongoURI mongolabUri = new MongoURI(System.getenv("MONGOLAB_URI") != null ? System.getenv("MONGOLAB_URI") : "mongodb://127.0.0.1:27017/hello");
        Mongo m = new Mongo(mongolabUri);
        mongoDB = m.getDB(mongolabUri.getDatabase());
        if ((mongolabUri.getUsername() != null) && (mongolabUri.getPassword() != null)) {
            mongoDB.authenticate(mongolabUri.getUsername(), mongolabUri.getPassword());
        }

        contentUrl = System.getenv("CONTENT_URL") != null ? System.getenv("CONTENT_URL") : CONTENT_PATH;

        Thread.currentThread().join();
View Full Code Here

    }

    @Provides
    Mongo create(final Application application) {
        try {
            return new Mongo(new MongoURI(application.configuration().getString("mongodb.uri")));
        } catch (UnknownHostException e) {
            addError(e);
            return null;
        }
    }
View Full Code Here

            String password = getProperty(properties, "password", null);
           
            try {
                Mongo mongo;
                if (mongoURI != null) {
                    MongoURI uri = new MongoURI(mongoURI);
                    mongo = new Mongo(uri);
                }
                else {
                    MongoOptions mongoOptions = createMongoOptions(properties);
                   
View Full Code Here

        if (_collection != null) return _collection;

        synchronized(sMutex) {
            if (_collection != null) return _collection;

            _mongo = new Mongo(new MongoURI(_mongoUri));

            final DB db = _mongo.getDB(_databaseName);

            _collection = _mongo.getDB(_databaseName).getCollection(_collectionName);
View Full Code Here

        properties = new Properties();
        InputStream is = MongoDbConversionsTest.class.getResourceAsStream("/mongodb.test.properties");
        properties.load(is);
        // ping Mongo and populate db and collection
        try {
            mongo = new Mongo(new MongoURI(properties.getProperty("mongodb.connectionURI")));
            mongo.getDatabaseNames();
            dbName = properties.getProperty("mongodb.testDb");
            db = mongo.getDB(dbName);
        } catch (Exception e) {
            Assume.assumeNoException(e);
View Full Code Here

        properties = new Properties();
        InputStream is = MongoDbConversionsTest.class.getResourceAsStream("/mongodb.test.properties");
        properties.load(is);
        // ping Mongo and populate db and collection
        try {
            mongo = new Mongo(new MongoURI(properties.getProperty("mongodb.connectionURI")));
            mongo.getDatabaseNames();
            dbName = properties.getProperty("mongodb.testDb");
            db = mongo.getDB(dbName);
        } catch (Exception e) {
            Assume.assumeNoException(e);
View Full Code Here

  @Autowired
  RepositoryApiConfiguration config;

  @Override
  public Mongo mongo() throws UnknownHostException {
    return new Mongo(new MongoURI(config.getMongoURLConnection()));
  }
View Full Code Here

  public static List<InputSplit> calculateSplits_phase2(InfiniteMongoConfig conf, BasicDBObject confQuery, boolean alwaysUseChunks, boolean newShardScheme, Integer splitDocCount)
  {
    alwaysUseChunks &= (conf.getMaxSplits() != MAX_SPLITS);
      // (in standalone mode, never use chunks)
   
    MongoURI uri = conf.getInputURI();
    DBCollection coll = InfiniteMongoConfigUtil.getCollection(uri);
    if (conf.getLimit() > 0) {
      return calculateManualSplits(conf, confQuery, 1, conf.getLimit(), coll);     
    }
    else
View Full Code Here

    public void startup() {
        _running.set(true);
        try {
            _lock.lock();

            _mongo = new Mongo(new MongoURI(_options.getMongoUri()));

            // Init the db/collection.
            LockDao.setup(_mongo, _options);
            if (_options.getEnableHistory()) LockHistoryDao.setup(_mongo, _options);
View Full Code Here

TOP

Related Classes of com.mongodb.MongoURI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.