mongo

mongo is a Change Type in the Liquibase Pro extension for MongoDB that allows you to specify mongosh statements in your changesets. In MongoDB changesets, use mongo instead of sql. For more information, see Welcome to MongoDB Shell (mongosh).

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.

However, you may want to specify additional or more complex MongoDB commands. You can use the mongo Change Type to directly specify mongosh statements in your XML, JSON, and YAML changelogs. Additionally, you can use the mongoFile Change Type to store your mongosh changes in a separate file and call on it from your changelog.

Note: If you want your changelog to be a JavaScript file rather than XML, YAML, or JSON, you can either use unformatted mongosh or format your mongosh according to Liquibase conventions to allow for better change tracking. For more information, see Use Native Executors with MongoDB Pro.

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

Tip: To use this Change Type, you must specify mongosh as the value for runWith in the changeset.

Available attributes

Name

Type

Description

Requirement

mongo

String

Specifies the mongosh to execute.

Required

dbms

String

Specifies which database type(s)a changeset will be used for. See valid database type names on dbms. Separate multiple databases with commas. Specify that a changeset is not applicable to a particular database type by prefixing with !.The keywords all and none are also available.

Optional

Note: The mongoFile Change Type does not exist in formatted mongosh changelogs. However, you can directly specify mongosh in YAML, JSON, or XML changelogs. For more information, see Use Native Executors with MongoDB Pro.

mongo examples

databaseChangeLog:
  - changeSet:
      id: 1
      author: your.name
      runWith: mongosh
      changes:
        - mongo:
            mongo: db.createCollection('person')
            dbms: mongodb
        - rollback:
            mongo:
              mongo: db.person.drop()