createCollection

createCollection is a Change Type in the Liquibase Open Source and Liquibase Pro extensions for MongoDB that creates a collection with the validator.

Uses

The Liquibase Pro extension for MongoDB includes several modeled Change Types from the Liquibase Open Source version. These let you specify a few MongoDB commands using Liquibase XML, JSON, and YAML changelogs.

createCollection is one such Change Type. You can use it to create a collection in your database.

To add data to your collection, you must use the insertOne and insertMany Change Types.

Note: If you want to specify mongosh statements in your XML, JSON, and YAML changelogs, use the mongo and mongoFile Change Types instead.

Run

To run this Change Type, follow these steps:

  1. Add the Change Type to your changeset, as shown in the examples on this page.

  2. Specify any required attributes. Use the table on this page to see which ones your database requires.

  3. Deploy your changeset by running the update command: liquibase update

Available attributes

Tip: You must specify all top-level attributes marked as required. If you specify an optional attribute, you must also specify any nested attributes that it requires.

Name

Type

Description

Requirement

collectionName

String

Name of the collection to create.

Required

Nested tags

Name

Type

Description

Requirement

options

String

Additional settings can be passed to MongoDB when creating collections, such as capped, size, and max. For more information, see db.createCollection().

Optional

createCollection examples

databaseChangeLog:
  - changeSet:
      id: 1
      author: your.name
      comment: create_collection_comment
      changes:
        - createCollection:
            collectionName: towns_yaml