org.piotr.apollo.mongo.migration.FinishedMigration.java Source code

Java tutorial

Introduction

Here is the source code for org.piotr.apollo.mongo.migration.FinishedMigration.java

Source

/*
 * 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 FinishedMigration {

    mongoDB mongo = new mongoDB();

    public FinishedMigration() {

        System.out.println("Finished migration : start");

        Boolean collExist = false;
        MongoDatabase db = mongo.getDatabase();
        MongoIterable<String> collectionNames = db.listCollectionNames();

        for (String colName : collectionNames) {
            if (colName.equals("finishedCollection"))
                collExist = true;
        }

        if (!collExist) {
            System.out.println("Creating collection: finishedCollection");
            db.createCollection("finishedCollection");
        }
        System.out.println("Finished migration : stop");
    }
}