Example usage for com.mongodb MongoURI getDatabase

List of usage examples for com.mongodb MongoURI getDatabase

Introduction

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

Prototype

@Nullable
public String getDatabase() 

Source Link

Document

Gets the database name.

Usage

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

License:Apache License

/**
 * Creates a new {@link SimpleMongoDbFactory} instance from the given {@link MongoURI}.
 * //from w  ww . j a v  a 2s.c  o  m
 * @param uri must not be {@literal null}.
 * @throws MongoException
 * @throws UnknownHostException
 * @see MongoURI
 * @deprecated since 1.7. Please use {@link #SimpleMongoDbFactory(MongoClientURI)} instead.
 */
@Deprecated
public SimpleMongoDbFactory(MongoURI uri) throws MongoException, UnknownHostException {
    this(new Mongo(uri), uri.getDatabase(),
            new UserCredentials(uri.getUsername(), parseChars(uri.getPassword())), true, uri.getDatabase());
}

From source file:v7views.mongo.InitMongo.java

License:Open Source License

public static V7Collection getCollection(ServletContext context, String name) {
    BSONBackedObject conf = getConfig(context);
    Object data = conf.getField("collections." + name);
    if (data instanceof String) {
        MongoURI uri = new MongoURI((String) data);
        return new V7Collection(getMongo(context).getDB(uri.getDatabase()).getCollection(uri.getCollection()));
    }/*  w  w w .j  a va2  s  .  c  o  m*/
    BSONBackedObject b = (BSONBackedObject) data;
    V7Collection base = getCollection(context, b.getStringField("collection"));
    return new V7Collection(base, b.getObjectField("filter"));
}