List of usage examples for com.mongodb MongoClient MongoClient
public MongoClient(final MongoClientURI uri)
From source file:com.github.krr.mongodb.aggregate.support.config.NonReactiveMongoClientTestConfiguration.java
License:Apache License
@Bean public MongoClient mongoClient() throws IOException { ServerAddress serverAddress = getServerAddress(); return new MongoClient(serverAddress); }
From source file:com.github.mongo.labs.helper.MongoQueryService.java
License:Apache License
@PostConstruct public void init() throws UnknownHostException { Main.initMongoProfiling();/* w ww .j a v a2 s . co m*/ DB db = new MongoClient("localhost").getDB("devoxx"); Jongo jongo = new Jongo(db); collection = jongo.getCollection("system.profile"); }
From source file:com.github.mongo.labs.Main.java
License:Apache License
public static void initMongoProfiling() { try {//from ww w .j a va 2 s .c o m // bye bye Mongo driver logs Logger.getLogger("com.mongodb").setLevel(Level.OFF); DB db = new MongoClient("localhost").getDB("devoxx"); Jongo jongo = new Jongo(db); ResultCmd r = jongo.getCollection("$cmd").withWriteConcern(WriteConcern.SAFE).findOne("{profile: 2}") .as(ResultCmd.class);// log event fast query System.err.println("profiling =" + r); } catch (IOException e) { throwMongoNotStarted(); } catch (MongoException e) { throwMongoNotStarted(); } }
From source file:com.glaf.core.container.MongodbContainer.java
License:Apache License
private synchronized void init() { if (mongoClient == null) { String servers = getString("servers"); if (servers == null) { servers = "127.0.0.1:27017"; }//from w ww. j av a 2 s. c o m List<String> list = StringTools.split(servers, ","); List<ServerAddress> addrList = new ArrayList<ServerAddress>(); for (String server : list) { String host = server.substring(0, server.indexOf(":")); int port = Integer.parseInt(server.substring(server.indexOf(":") + 1, server.length())); try { ServerAddress addr = new ServerAddress(host, port); addrList.add(addr); } catch (Exception ex) { ex.printStackTrace(); } } mongoClient = new MongoClient(addrList); mongoClient.setWriteConcern(WriteConcern.JOURNALED); Runnable shutdownHook = new MongodbShutdownHook(mongoClient); ShutdownHookManager.get().addShutdownHook(shutdownHook, Thread.NORM_PRIORITY); } }
From source file:com.google.api.ads.adwords.awreporting.model.persistence.mongodb.MongoEntityPersister.java
License:Open Source License
/** * Constructor that opens MongoDB client from URL, and retrives specified database. * * @param mongoConnectionUrl the Mongo connection url * @param mongoDataBaseName the Mongo database name */// ww w . j a v a 2 s .co m public MongoEntityPersister(String mongoConnectionUrl, String mongoDataBaseName) throws UnknownHostException, MongoException { mongoClient = new MongoClient(new MongoClientURI(mongoConnectionUrl)); db = mongoClient.getDB(mongoDataBaseName); }
From source file:com.google.api.ads.adwords.jaxws.extensions.report.model.persistence.mongodb.MongoEntityPersister.java
License:Open Source License
protected MongoEntityPersister(String mongoConnectionUrl, String mongoDataBaseName) throws UnknownHostException, MongoException { mongoClient = new MongoClient(new MongoClientURI(mongoConnectionUrl)); db = mongoClient.getDB(mongoDataBaseName); }
From source file:com.grallandco.util.MongoConnectionManager.java
License:Apache License
/** * Get the MongoDB client//ww w . j a v a2s. c om * @return */ public static MongoClient getMongoClient() { if (client == null) { // get the URU list form the configuration String mongoURIs = MongoDBCouchbaseReplicator.mongoUri; List<String> list = Arrays.asList(mongoURIs.split(",")); List<ServerAddress> addressList = new ArrayList<ServerAddress>(); try { for (String addr : list) { addressList.add(new ServerAddress(addr)); } client = new MongoClient(addressList); } catch (UnknownHostException e) { logger.log(Level.SEVERE, e.getMessage()); System.exit(1); } logger.log(Level.INFO, "MongoDB Replicator Connected to " + addressList); } return client; }
From source file:com.gs.obevo.mongodb.impl.MongoClientFactory.java
License:Apache License
private MongoClient getMongoClient(MongoClientURI mongoClientURI) { return new MongoClient(mongoClientURI); }
From source file:com.hantsylabs.example.spring.config.MongoConfig.java
@Override public Mongo mongo() throws Exception { Mongo mongo = new MongoClient("localhost"); return mongo; }
From source file:com.hazelcast.loader.MongoMapStore.java
License:Open Source License
@Override public void init(HazelcastInstance hazelcastInstance, Properties properties, String mapName) { String mongoUrl = (String) properties.get("mongo.url"); String dbName = (String) properties.get("mongo.db"); String collectionName = (String) properties.get("mongo.collection"); this.mongoClient = new MongoClient(new MongoClientURI(mongoUrl)); this.collection = mongoClient.getDatabase(dbName).getCollection(collectionName); }