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 LessonMigration { mongoDB mongo = new mongoDB(); public LessonMigration() { System.out.println("Lesson migration : start"); Boolean collExist = false; MongoDatabase db = mongo.getDatabase(); MongoIterable<String> collectionNames = db.listCollectionNames(); for (String colName : collectionNames) { if (colName.equals("lessonCollection")) collExist = true; } if (!collExist) { System.out.println("Creating collection: lessonCollection"); db.createCollection("lessonCollection"); } System.out.println("Lesson migration : stop"); } }