Example usage for com.mongodb.client MongoDatabase createCollection

List of usage examples for com.mongodb.client MongoDatabase createCollection

Introduction

In this page you can find the example usage for com.mongodb.client MongoDatabase createCollection.

Prototype

void createCollection(String collectionName);

Source Link

Document

Create a new collection with the given name.

Usage

From source file:org.piotr.apollo.mongo.migration.QuestionMigration.java

public QuestionMigration() {

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

    Boolean collExist = false;//  w w  w  .ja  v  a 2 s  .co  m
    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");
}

From source file:org.piotr.apollo.mongo.migration.SectionMigration.java

public SectionMigration() {

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

    Boolean collExist = false;//from  ww  w .  ja  v a 2s . c  om
    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");
}