List of usage examples for com.mongodb MongoClient getDatabase
public MongoDatabase getDatabase(final String databaseName)
From source file:com.exorath.service.hideplayers.service.MongoService.java
License:Apache License
public MongoService(MongoClient mongoClient, String databaseName) { this.visibilityPlayersCollection = mongoClient.getDatabase(databaseName).getCollection("visibilityPlayers"); }
From source file:com.focusit.log4jmongo.appender.SimpleMongoDbAppender.java
License:Apache License
protected MongoDatabase getDatabase(final MongoClient mongo, final String databaseName) { return mongo.getDatabase(databaseName); }
From source file:com.github.achatain.catalog.module.CatalogDatabaseModule.java
License:Open Source License
CatalogDatabaseModule(final MongoClient mongoClient) { this.mongoClient = mongoClient; this.systemDatabaseProvider = () -> mongoClient.getDatabase(SYSTEM_DATABASE); }
From source file:com.github.danzx.zekke.persistence.internal.mongo.MongoSequenceManager.java
License:Apache License
public @Inject MongoSequenceManager(MongoClient mongoClient, MongoDbSettings mongoSettings) { requireNonNull(mongoClient);//from www .j a v a 2 s . c o m requireNonNull(mongoSettings); database = mongoClient.getDatabase(mongoSettings.getDatabase()); sequencesCollection = database.getCollection(COLLECTION_NAME); }
From source file:com.github.frapontillo.pulse.crowd.data.repository.Repository.java
License:Apache License
/** * Create a new Repository using the default configuration in `database.properties` and * overriding the db name//from www.j a v a2s . c om * with the one in input. * * @param db The database name to use for this Repository instance. */ @SuppressWarnings({ "unchecked", "deprecation" }) public Repository(String db) { DBConfig config = new DBConfig(getClass(), db); MongoClient client = new MongoClient(config.getServerAddress(), config.getCredentials()); // map all Morphia classes morphia = new Morphia(); morphia.mapPackageFromClass(Message.class); ClusterSettings clusterSettings = ClusterSettings.builder() .hosts(Collections.singletonList(config.getServerAddress())).build(); MongoClientSettings settings = MongoClientSettings.builder().clusterSettings(clusterSettings) .credentialList(config.getCredentials()).build(); com.mongodb.reactivestreams.client.MongoClient rxClient = MongoClients.create(settings); // create and/or get the datastore datastore = morphia.createDatastore(client, config.getDBName()); // init the DAO initDAO(datastore); ensureIndexes(); // create the reactive database rxDatastore = rxClient.getDatabase(config.getDBName()); }
From source file:com.ibm.research.mongotx.daytrader.Load.java
License:Open Source License
public static void main(String[] args) throws Exception { //MongoClient client = new MongoClient(new MongoClientURI("mongodb://admin:admin@ds043714.mongolab.com:43714/?authSource=trade&authMechanism=SCRAM-SHA-1")); MongoClient client = new MongoClient("localhost"); TxDatabase txDB = new LatestReadCommittedTxDB(client, client.getDatabase("trade")); dropCollections(txDB);// w w w.ja va 2 s . co m populate(txDB); client.close(); }
From source file:com.ibm.research.mongotx.daytrader.MongoTrade.java
License:Open Source License
public MongoTrade() { MongoClient client; try {/*from w ww . ja va 2 s. c o m*/ client = new MongoClient(// System.getProperty("trade.mongo.url", "localhost"), // Integer.parseInt(System.getProperty("trade.mongo.port", "27017"))); } catch (Exception e) { throw new IllegalStateException(e); } MongoDatabase db = client.getDatabase(System.getProperty("trade.mongo.db", "trade")); txDB = new LatestReadCommittedTxDB(client, db); }
From source file:com.imaginea.mongodb.controllers.DocumentController.java
License:Apache License
/** * Maps GET Request to get all keys of document inside a collection inside a database present in * mongo db to a service function that returns the list. Also forms the JSON response for this * request and sent it to client. In case of any exception from the service files an error object * if formed./*from w ww.ja v a 2s . c om*/ * * @param dbName Name of Database * @param collectionName Name of Collection * @param connectionId Mongo Db Configuration provided by user to connect to. * @param request Get the HTTP request context to extract session parameters * @return A String of JSON format with all keys in a collection. */ @GET @Path("/keys") @Produces(MediaType.APPLICATION_JSON) public String getKeysRequest(@PathParam("dbName") final String dbName, @PathParam("collectionName") final String collectionName, @QueryParam("allKeys") final Boolean allKeys, @QueryParam("connectionId") final String connectionId, @Context final HttpServletRequest request) { String response = new ResponseTemplate().execute(logger, connectionId, request, new ResponseCallback() { public Object execute() throws Exception { // Perform the operation here only. MongoClient mongoInstance = authService.getMongoInstance(connectionId); long count = mongoInstance.getDatabase(dbName).getCollection(collectionName).count(); FindIterable<Document> findIterable = mongoInstance.getDatabase(dbName) .getCollection(collectionName).find(); if (!allKeys) { findIterable.limit(10); } MongoCursor<Document> cursor = findIterable.iterator(); Set<String> completeSet = new HashSet<String>(); if (cursor.hasNext()) { while (cursor.hasNext()) { Document doc = cursor.next(); getNestedKeys(doc, completeSet, ""); } } completeSet.remove("_id"); JSONObject result = new JSONObject(); result.put("keys", completeSet); result.put("count", count); return result; } }); return response; }
From source file:com.imaginea.mongodb.controllers.GraphController.java
License:Apache License
@GET @Path("/initiate") @Produces(MediaType.APPLICATION_JSON)/* w w w.ja va 2 s.c o m*/ public String initiateGraphsRequest(@QueryParam("connectionId") final String connectionId, @QueryParam("pollingTime") final String pollingTime, @Context final HttpServletRequest request) throws IOException { String result = new ResponseTemplate().execute(logger, connectionId, request, new ResponseCallback() { public Object execute() throws Exception { MongoClient mongoInstance = authService.getMongoInstance(connectionId); // Need a Db to get ServerStats MongoDatabase db = mongoInstance.getDatabase("admin"); Object result = null; if (pollingTime != null) { jump = Integer.parseInt(pollingTime); } result = processInitiate(db); return result; } }); return result; }
From source file:com.imaginea.mongodb.controllers.GraphController.java
License:Apache License
@GET @Path("/query") @Produces(MediaType.APPLICATION_JSON)/*from w ww. j a va 2 s.co m*/ public String queryGraphsRequest(@QueryParam("connectionId") final String connectionId, @Context final HttpServletRequest request) throws IOException { String result = new ResponseTemplate().execute(logger, connectionId, request, new ResponseCallback() { public Object execute() throws Exception { MongoClient mongoInstance = authService.getMongoInstance(connectionId); // Need a Db to get ServerStats MongoDatabase db = mongoInstance.getDatabase("admin"); Object result = null; result = processQuery(db); return result; } }); return result; }