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

@SuppressWarnings("deprecation")
    Mongo(final Cluster cluster, final MongoClientOptions options, final List<MongoCredential> credentialsList) 

Source Link

Usage

From source file:org.springframework.data.mongodb.core.MongoFactoryBean.java

License:Apache License

@Override
protected Mongo createInstance() throws Exception {

    Mongo mongo;// www . ja v  a2 s .  com
    ServerAddress defaultOptions = new ServerAddress();

    if (mongoOptions == null) {
        mongoOptions = new MongoOptions();
    }

    if (!isNullOrEmpty(replicaPair)) {
        if (replicaPair.size() < 2) {
            throw new CannotGetMongoDbConnectionException("A replica pair must have two server entries");
        }
        mongo = new Mongo(replicaPair.get(0), replicaPair.get(1), mongoOptions);
    } else if (!isNullOrEmpty(replicaSetSeeds)) {
        mongo = new Mongo(replicaSetSeeds, mongoOptions);
    } else {
        String mongoHost = StringUtils.hasText(host) ? host : defaultOptions.getHost();
        mongo = port != null ? new Mongo(new ServerAddress(mongoHost, port), mongoOptions)
                : new Mongo(mongoHost, mongoOptions);
    }

    if (writeConcern != null) {
        mongo.setWriteConcern(writeConcern);
    }

    return mongo;
}