/** * Constructor used for a basic template configuration. * * @param mongoClient must not be {@literal null}. * @param databaseName must not be {@literal null} or empty. */ public MongoTemplate(MongoClient mongoClient, String databaseName) { this(new SimpleMongoDbFactory(mongoClient, databaseName), (MongoConverter) null); }
@Bean public SimpleMongoDbFactory mongoDbFactory() throws Exception { UserCredentials userCredentials = new UserCredentials(user, password); SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new MongoClient(host, port), dbName, userCredentials); mongoDbFactory.setWriteConcern(WriteConcern.ACKNOWLEDGED); return mongoDbFactory; }
public SimpleMongoDbFactory configure(SimpleMongoDbFactory mongoDbFactory, MongoDbFactoryConfig config) { if (config != null && config.getWriteConcern() != null) { WriteConcern writeConcern = WriteConcern.valueOf(config.getWriteConcern()); if (writeConcern != null) { mongoDbFactory.setWriteConcern(writeConcern); } } return mongoDbFactory; } }
@Override public DB getDb() { final String tlName = dbName.get(); final String dbToUse = (tlName != null ? tlName : this.defaultName); logger.debug("Acquiring database: " + dbToUse); createIndexIfNecessaryFor(dbToUse); return super.getDb(dbToUse); }
@Bean @Profile("!unittest") MongoDbFactory mongoDbFactory() throws UnknownHostException { SimpleMongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongo(), mongoProperties.getDatabase()); mongoDbFactory.setWriteConcern(WriteConcern.ACKNOWLEDGED); return mongoDbFactory; }
public SimpleMongoDbFactory configure(SimpleMongoDbFactory mongoDbFactory, MongoDbFactoryConfig config) { if (config != null && config.getWriteConcern() != null) { WriteConcern writeConcern = WriteConcern.valueOf(config.getWriteConcern()); if (writeConcern != null) { mongoDbFactory.setWriteConcern(writeConcern); } } return mongoDbFactory; } }
@Bean @Primary public MongoDbFactory primaryFactory(MongoProperties mongo) throws Exception { return new SimpleMongoDbFactory(new MongoClient(mongo.getHost(), mongo.getPort()), mongo.getDatabase()); }
public MongoDbFactory createService(MongoServiceInfo serviceInfo) { try { SimpleMongoDbFactory mongoDbFactory; if (serviceInfo.getUri() != null) { mongoDbFactory = new SimpleMongoDbFactory(new MongoURI(serviceInfo.getUri())); } else { UserCredentials credentials = new UserCredentials(serviceInfo.getUserName(), serviceInfo.getPassword()); ServerAddress serverAddress = new ServerAddress(serviceInfo.getHost(), serviceInfo.getPort()); MongoOptions mongoOptionsToUse = getMongoOptions(); Mongo mongo; if (mongoOptionsToUse != null) { mongo = new Mongo(serverAddress, mongoOptionsToUse); } else { mongo = new Mongo(serverAddress); } mongoDbFactory = new SimpleMongoDbFactory(mongo, serviceInfo.getDatabase(), credentials); } if (cloudMongoConfiguration != null && cloudMongoConfiguration.getWriteConcern() != null) { WriteConcern writeConcern = WriteConcern.valueOf(cloudMongoConfiguration.getWriteConcern()); if (writeConcern != null) { mongoDbFactory.setWriteConcern(writeConcern); } } return mongoDbFactory; } catch (UnknownHostException e) { throw new CloudServiceException(e); } catch (MongoException e) { throw new CloudServiceException(e); } }
public SimpleMongoDbFactory configure(SimpleMongoDbFactory mongoDbFactory, MongoDbFactoryConfig config) { if (config != null && config.getWriteConcern() != null) { WriteConcern writeConcern = WriteConcern.valueOf(config.getWriteConcern()); if (writeConcern != null) { mongoDbFactory.setWriteConcern(writeConcern); } } return mongoDbFactory; }
@Bean public MongoDbFactory secondaryFactory(MongoProperties mongo) throws Exception { return new SimpleMongoDbFactory(new MongoClient(mongo.getHost(), mongo.getPort()), mongo.getDatabase()); } }
public SimpleMongoDbFactory configure(SimpleMongoDbFactory mongoDbFactory, MongoDbFactoryConfig config) { if (config != null && config.getWriteConcern() != null) { WriteConcern writeConcern = WriteConcern.valueOf(config.getWriteConcern()); if (writeConcern != null) { mongoDbFactory.setWriteConcern(writeConcern); } } return mongoDbFactory; } }
/** * Creates a {@link SimpleMongoDbFactory} to be used by the {@link MongoTemplate}. Will use the {@link MongoClient} * instance configured in {@link #mongoClient()}. * * @see #mongoClient() * @see #mongoTemplate() * @return */ @Bean public MongoDbFactory mongoDbFactory() { return new SimpleMongoDbFactory(mongoClient(), getDatabaseName()); }
public static MongoDbFactory prepareMongoFactory(String... additionalCollectionToDrop) throws Exception{ MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new MongoClient(), "test"); MongoTemplate template = new MongoTemplate(mongoDbFactory); template.dropCollection("messages"); template.dropCollection("data"); for (String additionalCollection : additionalCollectionToDrop) { template.dropCollection(additionalCollection); } return mongoDbFactory; } }
/** * Constructor used for a basic template configuration. * * @param mongoClient must not be {@literal null}. * @param databaseName must not be {@literal null} or empty. */ public MongoTemplate(MongoClient mongoClient, String databaseName) { this(new SimpleMongoDbFactory(mongoClient, databaseName), (MongoConverter) null); }
mongoClient = new MongoClient(seeds, credentials, options); MongoDbFactory dbFactory = new SimpleMongoDbFactory(mongoClient, configuration.getDbName());
/** * Creates a {@link SimpleMongoDbFactory} to be used by the {@link MongoTemplate}. Will use the {@link MongoClient} * instance configured in {@link #mongoClient()}. * * @see #mongoClient() * @see #mongoTemplate() * @return */ @Bean public MongoDbFactory mongoDbFactory() { return new SimpleMongoDbFactory(mongoClient(), getDatabaseName()); }
@Bean public MongoDbFactory mongoDbFactory() { return new SimpleMongoDbFactory(new MongoClient(), "test"); }
@Override protected MongoDbMessageStore getMessageGroupStore() throws Exception { MongoDbMessageStore mongoDbMessageStore = new MongoDbMessageStore(new SimpleMongoDbFactory(new MongoClient(), "test")); mongoDbMessageStore.afterPropertiesSet(); return mongoDbMessageStore; }
@Override protected MessageStore getMessageStore() throws Exception { MongoDbMessageStore mongoDbMessageStore = new MongoDbMessageStore(new SimpleMongoDbFactory(new MongoClient(), "test")); mongoDbMessageStore.afterPropertiesSet(); return mongoDbMessageStore; }
protected MongoDbFactory prepareMongoFactory(String... additionalCollectionsToDrop) { MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new MongoClient(), "test"); cleanupCollections(mongoDbFactory, additionalCollectionsToDrop); return mongoDbFactory; }