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

Java tutorial

Introduction

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

    mongoDB mongo = new mongoDB();

    public QuestionMigration() {

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

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

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

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