Example usage for com.mongodb Mongo Mongo

List of usage examples for com.mongodb Mongo Mongo

Introduction

In this page you can find the example usage for com.mongodb Mongo Mongo.

Prototype

@Deprecated
public Mongo() 

Source Link

Document

Creates a Mongo instance based on a (single) mongodb node (localhost, default port)

Usage

From source file:cascading.mongodb.MongoWrapper.java

License:Apache License

static private Mongo makeInstance() throws UnknownHostException {
    return new Mongo();
}

From source file:ch.windmobile.server.mongo.MongoDataSource.java

License:Open Source License

public MongoDataSource() {
    try {// w  w w.j av a  2 s  .  c  om
        mongoService = new Mongo();
    } catch (UnknownHostException e) {
    }
    database = mongoService.getDB("windmobile");
}

From source file:ch.windmobile.server.social.mongodb.MongoDBServiceLocator.java

License:Open Source License

public synchronized ServiceLocator connect(String url) throws ServiceLocatorException {
    if (mongoService != null) {
        return this;
    }//from w w  w .  j  a  v a2s. c  o m
    try {
        if (url == null) {
            mongoService = new Mongo();
        } else {
            mongoService = new Mongo(url);
        }
    } catch (UnknownHostException e) {
        throw new ServiceLocatorException(e);
    } catch (MongoException e) {
        throw new ServiceLocatorException(e);
    }
    database = mongoService.getDB(MongoDBConstants.DATABASE_NAME);
    return this;
}

From source file:com.continuent.tungsten.replicator.applier.MongoApplier.java

License:Open Source License

/**
 * {@inheritDoc}//from   ww w  .  j  a va 2 s  .c  om
 * 
 * @see com.continuent.tungsten.replicator.plugin.ReplicatorPlugin#prepare(com.continuent.tungsten.replicator.plugin.PluginContext)
 */
@Override
public void prepare(PluginContext context) throws ReplicatorException, InterruptedException {
    // Connect to MongoDB.
    if (logger.isDebugEnabled()) {
        logger.debug("Connecting to MongoDB: connectString=" + connectString);
    }
    m = null;
    try {
        if (connectString == null)
            m = new Mongo();
        else
            m = new Mongo(connectString);
    } catch (Exception e) {
        throw new ReplicatorException("Unable to connect to MongoDB: connection=" + this.connectString, e);
    }

    // Initialize table metadata cache.
    tableMetadataCache = new TableMetadataCache(5000);
}

From source file:com.example.config.AppConfig.java

public @Bean MongoDbFactory mongoDbFactory() throws Exception {
    UserCredentials userCredentials = new UserCredentials("joe", "secret");
    //return new SimpleMongoDbFactory(new Mongo(), "database", userCredentials);
    return new SimpleMongoDbFactory(new Mongo(), "test");
}

From source file:com.github.jmkgreen.morphia.Morphia.java

License:Apache License

/**
 * This will create a new Mongo instance; it is best to use a Mongo singleton instance
 *//*from w w w  .j a  v a  2s . co  m*/
@Deprecated
public Datastore createDatastore(String dbName, String user, char[] pw) {
    try {
        return createDatastore(new Mongo(), dbName, user, pw);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.ijuru.ijambo.Context.java

License:Open Source License

/**
 * Connects to the database/*  w  ww. j  av a2 s  .  co m*/
 * @return the Mongo DB
 * @throws ParseException
 * @throws UnknownHostException
 */
public static DB connectDatabase() throws ParseException, UnknownHostException {

    // Check for AppFog environment
    String appFogEnv = System.getenv("VCAP_SERVICES");

    if (appFogEnv != null) {
        // Connect to MongoDB as AppFog service
        JSONParser parser = new JSONParser();
        JSONObject svcs = (JSONObject) parser.parse(appFogEnv);
        JSONArray mongoSettings = (JSONArray) svcs.get("mongodb-1.8");
        JSONObject mongoSettings0 = (JSONObject) mongoSettings.get(0);
        JSONObject mongoCreds0 = (JSONObject) mongoSettings0.get("credentials");
        //String db = (String)mongoCreds0.get("db");
        String connectionURL = (String) mongoCreds0.get("url");

        log.info("Running as AppFog instance with connection URL: " + connectionURL);

        DB db = new MongoURI(connectionURL).connectDB();

        // https://jira.mongodb.org/browse/JAVA-436
        db.authenticate((String) mongoCreds0.get("username"),
                ((String) mongoCreds0.get("password")).toCharArray());

        return db;
    }

    // Create default MongoDB instance
    m = new Mongo();
    return m.getDB("ijambo");
}

From source file:com.ikanow.infinit.e.data_model.store.MongoDbConnection.java

License:Apache License

/** 
  * Class Constructor used to establish the mongo object
 * @throws MongoException //from w  w w.ja  va 2 s  . c  o m
 * @throws UnknownHostException 
  */
public MongoDbConnection() throws UnknownHostException, MongoException {
    // Test to see of the mongo object is populated
    if (mongo == null)
        mongo = new Mongo();
}

From source file:com.jhkt.playgroundArena.shared.tasks.MongoDBTaskRunner.java

License:Apache License

public MongoDBTaskRunner() throws UnknownHostException {
    super();//from   w  ww .  j a  v a  2s.co  m

    _hostNameIdentifier = DEFAULT_MONGO_HOSTNAME + DEFAULT_MONGO_PORT;

    if ((_instanceWrapper = _mongoMaps.get(_hostNameIdentifier)) == null) {
        _instanceWrapper = new ServerConnectionWrapper<Mongo>(new Mongo());
        _mongoMaps.put(_hostNameIdentifier, _instanceWrapper);
    }

    _instanceWrapper.incrementCount();
}

From source file:com.linuxbox.enkive.audit.mongodb.MongoAuditService.java

License:Open Source License

public MongoAuditService(String database, String collection) throws UnknownHostException, MongoException {
    this(new Mongo(), database, collection);
    createdMongo = true;/* w  ww.  j ava  2s.  co  m*/
}