Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package org.piotr.apollo.mongo.migration; import com.mongodb.client.MongoDatabase; import com.mongodb.client.MongoIterable; import org.piotr.apollo.database.mongoDB; /** * * @author Leniwiec */ public class SectionMigration { mongoDB mongo = new mongoDB(); public SectionMigration() { System.out.println("Section migration : start"); Boolean collExist = false; MongoDatabase db = mongo.getDatabase(); MongoIterable<String> collectionNames = db.listCollectionNames(); for (String colName : collectionNames) { if (colName.equals("sectionCollection")) collExist = true; } if (!collExist) { System.out.println("Creating collection: sectionCollection"); db.createCollection("sectionCollection"); } System.out.println("Section migration : stop"); } }