List of usage examples for com.mongodb MongoClientURI getCollection
@Nullable
public String getCollection()
From source file:org.apache.drill.exec.store.mongo.config.MongoPersistentStoreProvider.java
License:Apache License
@Override public void start() throws IOException { MongoClientURI clientURI = new MongoClientURI(mongoURL); client = new MongoClient(clientURI); MongoDatabase db = client.getDatabase(clientURI.getDatabase()); collection = db.getCollection(clientURI.getCollection()).withWriteConcern(WriteConcern.JOURNALED); Bson index = Indexes.ascending(pKey); collection.createIndex(index);/*www .j ava2 s. co m*/ }
From source file:org.apache.drill.exec.store.mongo.config.MongoPStoreProvider.java
License:Apache License
@Override public void start() throws IOException { MongoClientURI clientURI = new MongoClientURI(mongoURL); client = new MongoClient(clientURI); DB db = client.getDB(clientURI.getDatabase()); collection = db.getCollection(clientURI.getCollection()); collection.setWriteConcern(WriteConcern.JOURNALED); DBObject index = new BasicDBObject(1).append(pKey, Integer.valueOf(1)); collection.createIndex(index);/* w ww. j a va 2 s. c om*/ }
From source file:org.culturegraph.mf.mongodb.common.SimpleMongoDBConnection.java
License:Apache License
/** * @param uri/*from w w w .ja v a 2 s.c o m*/ * monogdb://user:pass@host:port/database.collection?options... * @see MongoClientURI */ public SimpleMongoDBConnection(final String uri) throws UnknownHostException { final MongoClientURI mongoClientUri = new MongoClientURI(uri); mongoClient = new MongoClient(mongoClientUri); final DB db = mongoClient.getDB(mongoClientUri.getDatabase()); dbCollection = db.getCollection(mongoClientUri.getCollection()); }
From source file:org.jberet.support.io.MongoItemReaderWriterBase.java
License:Open Source License
protected void init() throws Exception { if (beanType == null) { throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, null, "beanType"); }/*from www .ja v a2 s. c o m*/ if (mongoClientLookup == null) { final MongoClientURI clientURI; if (uri != null) { clientURI = new MongoClientURI(uri); if (database == null) { database = clientURI.getDatabase(); } if (collection == null) { collection = clientURI.getCollection(); } } else { clientURI = MongoClientObjectFactory.createMongoClientURI(host, database, collection, options, user, password); } mongoClient = (MongoClient) Mongo.Holder.singleton().connect(clientURI); } else { mongoClient = InitialContext.doLookup(mongoClientLookup); } db = mongoClient.getDB(database); jacksonCollection = JacksonDBCollection.wrap(db.getCollection(collection), beanType, String.class); }
From source file:org.netbeans.modules.mongodb.native_tools.MongoDumpExecAction.java
License:Open Source License
private void parseOptionsFromURI(MongoClientURI uri, Map<String, String> options) { if (uri.getUsername() != null && uri.getUsername().isEmpty() == false) { options.put(MongoDumpOptions.USERNAME, uri.getUsername()); }/*from w w w.java 2 s.c o m*/ if (uri.getPassword() != null && uri.getPassword().length > 0) { options.put(MongoDumpOptions.PASSWORD, new String(uri.getPassword())); } if (uri.getHosts() != null && uri.getHosts().isEmpty() == false) { final String hostWithPort = uri.getHosts().get(0); final Pattern p = Pattern.compile("(.*)(:(\\d+))?"); final Matcher m = p.matcher(hostWithPort); if (m.matches()) { final String host = m.group(1); final String port = m.group(3); if (host.isEmpty() == false) { options.put(MongoDumpOptions.HOST, host); if (port != null) { options.put(MongoDumpOptions.PORT, port); } } } } if (uri.getDatabase() != null && uri.getDatabase().isEmpty() == false) { options.put(MongoDumpOptions.DB, uri.getDatabase()); } if (uri.getCollection() != null && uri.getCollection().isEmpty() == false) { options.put(MongoDumpOptions.COLLECTION, uri.getCollection()); } }
From source file:org.netbeans.modules.mongodb.native_tools.MongoRestoreExecAction.java
License:Open Source License
private void parseOptionsFromURI(MongoClientURI uri, Map<String, String> options) { if (uri.getUsername() != null && uri.getUsername().isEmpty() == false) { options.put(MongoRestoreOptions.USERNAME, uri.getUsername()); }// ww w. ja v a 2 s .c o m if (uri.getPassword() != null && uri.getPassword().length > 0) { options.put(MongoRestoreOptions.PASSWORD, new String(uri.getPassword())); } if (uri.getHosts() != null && uri.getHosts().isEmpty() == false) { final String hostWithPort = uri.getHosts().get(0); final Pattern p = Pattern.compile("(.*)(:(\\d+))?"); final Matcher m = p.matcher(hostWithPort); if (m.matches()) { final String host = m.group(1); final String port = m.group(3); if (host.isEmpty() == false) { options.put(MongoRestoreOptions.HOST, host); if (port != null) { options.put(MongoRestoreOptions.PORT, port); } } } } if (uri.getDatabase() != null && uri.getDatabase().isEmpty() == false) { options.put(MongoRestoreOptions.DB, uri.getDatabase()); } if (uri.getCollection() != null && uri.getCollection().isEmpty() == false) { options.put(MongoRestoreOptions.COLLECTION, uri.getCollection()); } }
From source file:rapture.mongodb.MongoDBFactory.java
License:Open Source License
private Mongo getMongoFromLocalConfig(String instanceName) { String mongoHost = MultiValueConfigLoader.getConfig("MONGODB-" + instanceName); log.info("Host is " + mongoHost); if (StringUtils.isBlank(mongoHost)) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, mongoMsgCatalog.getMessage("NoHost")); }//www.j a va2s. co m MongoClientURI uri = new MongoClientURI(mongoHost); log.info("Username is " + uri.getUsername()); log.info("Host is " + uri.getHosts().toString()); log.info("DBName is " + uri.getDatabase()); log.info("Collection is " + uri.getCollection()); try { MongoClient mongo = new MongoClient(uri); mongoDBs.put(instanceName, mongo.getDB(uri.getDatabase())); mongoDatabases.put(instanceName, mongo.getDatabase(uri.getDatabase())); mongoInstances.put(instanceName, mongo); return mongo; } catch (MongoException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, new ExceptionToString(e)); } }