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

Java tutorial

Introduction

Here is the source code for org.piotr.apollo.mongo.migration.AnswerMigration.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 AnswerMigration {

    mongoDB mongo = new mongoDB();

    public AnswerMigration() {

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

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

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

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