Search in sources :

Example 96 with MongoClient

use of com.mongodb.MongoClient in project sling by apache.

the class MongoDBNoSqlResourceProviderFactory method activate.

@Activate
private void activate(ComponentContext componentContext, Map<String, Object> config) {
    String connectionString = PropertiesUtil.toString(config.get(CONNECTION_STRING_PROPERTY), CONNECTION_STRING_DEFAULT);
    String database = PropertiesUtil.toString(config.get(DATABASE_PROPERTY), DATABASE_DEFAULT);
    String collection = PropertiesUtil.toString(config.get(COLLECTION_PROPERTY), COLLECTION_DEFAULT);
    mongoClient = new MongoClient(connectionString);
    NoSqlAdapter mongodbAdapter = new MongoDBNoSqlAdapter(mongoClient, database, collection);
    // enable call logging and metrics for {@link MongoDBNoSqlAdapter}
    noSqlAdapter = new MetricsNoSqlAdapterWrapper(mongodbAdapter, LoggerFactory.getLogger(MongoDBNoSqlAdapter.class));
}
Also used : NoSqlAdapter(org.apache.sling.nosql.generic.adapter.NoSqlAdapter) MongoClient(com.mongodb.MongoClient) MetricsNoSqlAdapterWrapper(org.apache.sling.nosql.generic.adapter.MetricsNoSqlAdapterWrapper) Activate(org.apache.felix.scr.annotations.Activate)

Example 97 with MongoClient

use of com.mongodb.MongoClient in project GeoGig by boundlessgeo.

the class MongoGraphDatabaseTest method createDatabase.

@Override
protected MongoGraphDatabase createDatabase(Platform platform) throws Exception {
    final IniMongoProperties properties = new IniMongoProperties();
    final String uri = properties.get("mongodb.uri", String.class).or("mongodb://localhost:27017/");
    final String database = properties.get("mongodb.database", String.class).or("geogig");
    MongoClient client = new MongoClient(new MongoClientURI(uri));
    DB db = client.getDB(database);
    db.dropDatabase();
    MongoConnectionManager manager = new MongoConnectionManager();
    ConfigDatabase config = new TestConfigDatabase(platform);
    MongoGraphDatabase mongoGraphDatabase = new MongoGraphDatabase(manager, config);
    return mongoGraphDatabase;
}
Also used : MongoClient(com.mongodb.MongoClient) MongoGraphDatabase(org.locationtech.geogig.storage.mongo.MongoGraphDatabase) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) MongoClientURI(com.mongodb.MongoClientURI) MongoConnectionManager(org.locationtech.geogig.storage.mongo.MongoConnectionManager) DB(com.mongodb.DB)

Example 98 with MongoClient

use of com.mongodb.MongoClient in project java-design-patterns by iluwatar.

the class MongoTicketRepository method connect.

/**
 * Connect to database with given parameters
 */
public void connect(String dbName, String ticketsCollectionName, String countersCollectionName) {
    if (mongoClient != null) {
        mongoClient.close();
    }
    mongoClient = new MongoClient(System.getProperty("mongo-host"), Integer.parseInt(System.getProperty("mongo-port")));
    database = mongoClient.getDatabase(dbName);
    ticketsCollection = database.getCollection(ticketsCollectionName);
    countersCollection = database.getCollection(countersCollectionName);
    if (countersCollection.count() <= 0) {
        initCounters();
    }
}
Also used : MongoClient(com.mongodb.MongoClient)

Example 99 with MongoClient

use of com.mongodb.MongoClient in project java-design-patterns by iluwatar.

the class MongoEventLog method connect.

/**
 * Connect to database with given parameters
 */
public void connect(String dbName, String eventsCollectionName) {
    if (mongoClient != null) {
        mongoClient.close();
    }
    mongoClient = new MongoClient(System.getProperty("mongo-host"), Integer.parseInt(System.getProperty("mongo-port")));
    database = mongoClient.getDatabase(dbName);
    eventsCollection = database.getCollection(eventsCollectionName);
}
Also used : MongoClient(com.mongodb.MongoClient)

Example 100 with MongoClient

use of com.mongodb.MongoClient in project java-design-patterns by iluwatar.

the class MongoBankTest method init.

@BeforeEach
public void init() {
    MongoConnectionPropertiesLoader.load();
    MongoClient mongoClient = new MongoClient(System.getProperty("mongo-host"), Integer.parseInt(System.getProperty("mongo-port")));
    mongoClient.dropDatabase(TEST_DB);
    mongoClient.close();
    mongoBank = new MongoBank(TEST_DB, TEST_ACCOUNTS_COLLECTION);
}
Also used : MongoClient(com.mongodb.MongoClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MongoClient (com.mongodb.MongoClient)126 Test (org.junit.Test)31 MongoClientURI (com.mongodb.MongoClientURI)29 Document (org.bson.Document)26 ServerAddress (com.mongodb.ServerAddress)21 MongoDatabase (com.mongodb.client.MongoDatabase)21 Before (org.junit.Before)20 BasicDBObject (com.mongodb.BasicDBObject)11 ArrayList (java.util.ArrayList)11 MongoCredential (com.mongodb.MongoCredential)9 MongoException (com.mongodb.MongoException)8 DB (com.mongodb.DB)7 DBCollection (com.mongodb.DBCollection)7 UnknownHostException (java.net.UnknownHostException)7 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)7 DBObject (com.mongodb.DBObject)6 MongoClientOptions (com.mongodb.MongoClientOptions)6 IOException (java.io.IOException)5 List (java.util.List)5 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)5