package com.newfiber.termite.schedule; import com.mongodb.BasicDBObject; import java.util.Set; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.stereotype.Component; @Slf4j @Component public class MongoIndexSchedule { @Resource private MongoTemplate mongoTemplate; // @Scheduled(cron = "0 0 0 * * ? ") public void createIndex() { Set<String> setList = mongoTemplate.getCollectionNames(); for(String stCode : setList){ BasicDBObject defaultIndex = new BasicDBObject(); defaultIndex.put("sn", 1); defaultIndex.put("date", 1); mongoTemplate.getCollection(stCode).createIndex(defaultIndex); } } }