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

Mongo(final MongoClientURI mongoURI, @Nullable final MongoDriverInformation mongoDriverInformation) 

Source Link

Usage

From source file:nl.vu.psy.relic.persistence.mongo.MongoStore.java

License:Open Source License

public MongoStore(String host, int port, String dbname, String collection) throws RelicException {
    try {/*from ww w  .j av a  2 s  . co  m*/
        mongo = new Mongo(host, port);
        db = mongo.getDB(dbname);
        if (db.collectionExists(collection)) {
            relicCollection = db.getCollection(collection);
        } else {
            DBObject dbo = new BasicDBObject();
            dbo.put("capped", false);
            relicCollection = db.createCollection(collection, dbo);
        }
        relicCollection.ensureIndex(new BasicDBObject("relic.identifier", 1).append("unique", true));
        relicCollection.ensureIndex(new BasicDBObject("resolver.identifier", 1).append("unique", true));
    } catch (UnknownHostException e) {
        throw new RelicException("Unknown host for mongo connection.", e);
    } catch (MongoException e) {
        throw new RelicException("An exception from MongoDB was encountered,", e);
    }
}

From source file:nl.vu.psy.relic.persistence.mongo.MongoStore.java

License:Open Source License

public MongoStore(String host, int port, String dbname, String collection, String user, String pass)
        throws RelicException {
    try {/*from   www .ja  v a2 s.  c o m*/
        mongo = new Mongo(host, port);
        db = mongo.getDB(dbname);
        if (db.authenticate(user, pass.toCharArray())) {
            if (db.collectionExists(collection)) {
                relicCollection = db.getCollection(collection);
            } else {
                DBObject dbo = new BasicDBObject();
                dbo.put("capped", false);
                relicCollection = db.createCollection(collection, dbo);
            }
            relicCollection.ensureIndex(new BasicDBObject("relic.identifier", 1).append("unique", true));
            relicCollection.ensureIndex(new BasicDBObject("resolver.identifier", 1).append("unique", true));
        } else {
            throw new RelicException("Unable to authenticate.");
        }
    } catch (UnknownHostException e) {
        throw new RelicException("Unknown host for mongo connection.", e);
    } catch (MongoException e) {
        throw new RelicException("An exception from MongoDB was encountered,", e);
    }
}

From source file:nl.vu.psy.rite.persistence.mongo.MongoCommandStore.java

License:Open Source License

public MongoCommandStore(String host, int port, String dbname, String collection) throws RiteException {
    try {//from  w  ww.j ava  2s . c  om
        mongo = new Mongo(host, port);
        db = mongo.getDB(dbname);
        if (db.collectionExists(collection)) {
            commandCollection = db.getCollection(collection);
        } else {
            DBObject dbo = new BasicDBObject();
            dbo.put("capped", false);
            commandCollection = db.createCollection(collection, dbo);
        }
        commandCollection.ensureIndex(new BasicDBObject("clientcommand.clientid", 1).append("unique", true));
    } catch (UnknownHostException e) {
        throw new RiteException("Unknown host for mongo connection.", e);
    } catch (MongoException e) {
        throw new RiteException("An exception from MongoDB was encountered.", e);
    }
}

From source file:nl.vu.psy.rite.persistence.mongo.MongoCommandStore.java

License:Open Source License

public MongoCommandStore(String host, int port, String dbname, String collection, String user, String pass)
        throws RiteException {
    try {/* w  ww  .  j a  v  a  2 s.  co  m*/
        mongo = new Mongo(host, port);
        db = mongo.getDB(dbname);
        if (db.authenticate(user, pass.toCharArray())) {
            if (db.collectionExists(collection)) {
                commandCollection = db.getCollection(collection);
            } else {
                DBObject dbo = new BasicDBObject();
                dbo.put("capped", false);
                commandCollection = db.createCollection(collection, dbo);
            }
            commandCollection
                    .ensureIndex(new BasicDBObject("clientcommand.clientid", 1).append("unique", true));
        } else {
            throw new RiteException("Unable to authenticate.");
        }
    } catch (UnknownHostException e) {
        throw new RiteException("Unknown host for mongo connection.", e);
    } catch (MongoException e) {
        throw new RiteException("An exception from MongoDB was encountered,", e);
    }
}

From source file:nl.vu.psy.rite.persistence.mongo.MongoInfoStore.java

License:Open Source License

public MongoInfoStore(String host, int port, String dbname, String collection) throws RiteException {
    try {/* w ww.  ja  v a 2  s.  co  m*/
        mongo = new Mongo(host, port);
        db = mongo.getDB(dbname);
        if (db.collectionExists(collection)) {
            infoCollection = db.getCollection(collection);
        } else {
            DBObject dbo = new BasicDBObject();
            dbo.put("capped", false);
            infoCollection = db.createCollection(collection, dbo);
        }
        infoCollection.ensureIndex(new BasicDBObject("clientinfo.clientid", 1).append("unique", true));
    } catch (UnknownHostException e) {
        throw new RiteException("Unknown host for mongo connection.", e);
    } catch (MongoException e) {
        throw new RiteException("An exception from MongoDB was encountered.", e);
    }
}

From source file:nl.vu.psy.rite.persistence.mongo.MongoInfoStore.java

License:Open Source License

public MongoInfoStore(String host, int port, String dbname, String collection, String user, String pass)
        throws RiteException {
    try {/*from  w w  w. ja v  a2 s . c  o m*/
        mongo = new Mongo(host, port);
        db = mongo.getDB(dbname);
        if (db.authenticate(user, pass.toCharArray())) {
            if (db.collectionExists(collection)) {
                infoCollection = db.getCollection(collection);
            } else {
                DBObject dbo = new BasicDBObject();
                dbo.put("capped", false);
                infoCollection = db.createCollection(collection, dbo);
            }
            infoCollection.ensureIndex(new BasicDBObject("clientinfo.clientid", 1).append("unique", true));
        } else {
            throw new RiteException("Unable to authenticate.");
        }
    } catch (UnknownHostException e) {
        throw new RiteException("Unknown host for mongo connection.", e);
    } catch (MongoException e) {
        throw new RiteException("An exception from MongoDB was encountered,", e);
    }
}

From source file:nl.vu.psy.rite.persistence.mongo.MongoRecipeStore.java

License:Open Source License

public MongoRecipeStore(String host, int port, String dbname, String collection) throws RiteException {
    try {//ww w. j  av a  2  s . c  o m
        mongo = new Mongo(host, port);
        db = mongo.getDB(dbname);
        if (db.collectionExists(collection)) {
            recipeCollection = db.getCollection(collection);
        } else {
            DBObject dbo = new BasicDBObject();
            dbo.put("capped", false);
            recipeCollection = db.createCollection(collection, dbo);
        }
        recipeCollection.ensureIndex(new BasicDBObject("recipe", 1).append("unique", true));
    } catch (UnknownHostException e) {
        throw new RiteException("Unknown host for mongo connection.", e);
    } catch (MongoException e) {
        throw new RiteException("An exception from MongoDB was encountered.", e);
    }
}

From source file:nl.vu.psy.rite.persistence.mongo.MongoRecipeStore.java

License:Open Source License

public MongoRecipeStore(String host, int port, String dbname, String collection, String user, String pass)
        throws RiteException {
    try {/*from ww w.jav  a2s.c  om*/
        mongo = new Mongo(host, port);
        db = mongo.getDB(dbname);
        if (db.authenticate(user, pass.toCharArray())) {
            if (db.collectionExists(collection)) {
                recipeCollection = db.getCollection(collection);
            } else {
                DBObject dbo = new BasicDBObject();
                dbo.put("capped", false);
                recipeCollection = db.createCollection(collection, dbo);
            }
            recipeCollection.ensureIndex(new BasicDBObject("recipe", 1).append("unique", true));
        } else {
            throw new RiteException("Unable to authenticate.");
        }
    } catch (UnknownHostException e) {
        throw new RiteException("Unknown host for mongo connection.", e);
    } catch (MongoException e) {
        throw new RiteException("An exception from MongoDB was encountered,", e);
    }
}

From source file:no.pritest.restapi.MongoDBProvider.java

License:Open Source License

private MongoDBProvider() throws MongoException, UnknownHostException {
    Configuration config = new Configuration(PropertiesHolder.getInstance());
    Mongo mongo = new Mongo(config.getDatabaseURL(), config.getDatabasePort());
    db = mongo.getDB(config.getDatabaseName());
}

From source file:org.alfresco.extension.wcmdeployment.mongodb.MongoDbDeploymentTarget.java

License:Open Source License

public void init() {
    log.trace("MongoDbDeploymentTarget.init()");

    try {/*from w ww.j  a  va  2  s. c  o  m*/
        mongo = new Mongo(hostname, port);
    } catch (UnknownHostException uhe) {
        // Tra-lala-lala I hate checked exceptions...
        throw new DeploymentException(
                "Unable to connect to MongoDB server at: " + hostname + ":" + String.valueOf(port), uhe);
    }

    deployments = new ConcurrentHashMap<String, Map<String, Object>>();
}