@Override public void createCollection(String collectionName) { try { if (!mongoTemplate.collectionExists(collectionName)) { mongoTemplate.createCollection(collectionName); } } catch (UncategorizedMongoDbException ex) { LOG.warn("Failed to create collection {} due to", collectionName, ex); } }
public <T> MongoCollection<Document> createCollection(Class<T> entityClass) { return createCollection(operations.determineCollectionName(entityClass)); }
mongoTemplate.createCollection(collName);
public <T> MongoCollection<Document> createCollection(Class<T> entityClass) { return createCollection(operations.determineCollectionName(entityClass)); }
@Override public void createCollection(String collectionName) { if (StringUtils.isEmpty(collectionName)) { collectionName = clz.getSimpleName(); } if (!mongoTemplate.collectionExists(collectionName)) { mongoTemplate.createCollection(collectionName); } };
SpringMongoConfig config = new SpringMongoConfig(); MongoTemplate template = config.mongoTemplate(); template.createCollection("someCollection");
@PostConstruct public void start() { mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION); if (!mongoTemplate.collectionExists("history")) { mongoTemplate.createCollection("history"); } Thread thread = new Thread(this); thread.start(); LOGGER.info("Historian collector started"); }
@PostConstruct public void updateMongoSchema() { Preconditions.checkState(StringUtils.isNotBlank(collectionName), "error starting Store, collectionName is null"); logger.info("updating Mongo schema ..."); if (!mongoTemplate.collectionExists(collectionName)) { logger.info("create collection '"+collectionName+"'"); mongoTemplate.createCollection(collectionName); } //tags_idx BasicDBObject keys = new BasicDBObject(F_TAGS, 1); mongoTemplate.getCollection(collectionName).ensureIndex(keys, collectionName+"_tags_idx", false); //hist collection if (keepHistory) { collectionNameHist = collectionName + "_hist"; if (!mongoTemplate.collectionExists(collectionNameHist)) { logger.info("create collection '"+collectionNameHist+"'"); mongoTemplate.createCollection(collectionNameHist); } keys = new BasicDBObject(F_RECORD_FK_ID, 1); mongoTemplate.getCollection(collectionNameHist).ensureIndex(keys, collectionNameHist+"_record_fk_idx", false); } }
@Override public void initializeResources() { if (!mongoTemplate.collectionExists(collectionName)) { mongoTemplate.createCollection(collectionName); } hashingElementManager.upgrade(); upgradeIndexes(); }
mongoTemplate.createCollection(collName);