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


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 mongoFile Change Type to store mongosh statements in a separate file and call on it from your XML, YAML, and JSON changelogs. Additionally, you can use the mongo Change Type to specify mongosh in your changelog itself.

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.


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:
  4. liquibase update

Available attributes

Name Type Description Requirement
path String Specifies the file path of the mongosh file to load. Required
dbms String

Specifies which database type(s) a changeset is to be used for. See valid database type names on Liquibase Database Tutorials. 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.

encoding String

Encoding used in the file specified in the path attribute. Default: UTF-8.

relativeToChangelogFile Boolean

Specifies whether the file path is relative to the changelog file rather than looked up in the search path. Default: false.



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

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

The Liquibase MongoDB Pro extension uses a unique mongodb-pro XML namespace and XSD files in the changelog header. However, the ext prefix used with other extensions is backwards-compatible:


    <changeSet id="1" author="" runWith="mongosh">
        <mongodb-pro:mongoFile dbms="mongodb" path="scriptFile.txt" relativeToChangelogFile="true"/>


  - changeSet:
      id: 1
      runWith: mongosh
        - mongoFile:
            path: "scriptFile.txt"
            dbms: mongodb
            relativeToChangelogFile: "true"
        - rollback:
              mongo: ""
  "databaseChangeLog": [
      "changeSet": {
        "id": "1",
        "author": "",
        "runWith": "mongosh",
        "changes": [
            "mongoFile": {
              "dbms": "mongodb",
              "path": "scriptFile.txt",
              "relativeToChangelogFile": true
        "rollback": [
            "mongo": {
              "mongo": ""

Database support

This Change Type is only supported for MongoDB. It does not support auto rollback.