Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renameCollection feature #369

Open
isalciuc opened this issue May 18, 2023 · 2 comments
Open

renameCollection feature #369

isalciuc opened this issue May 18, 2023 · 2 comments

Comments

@isalciuc
Copy link

I didn't find any way to rename a collection in MongoDB using Liquibase

@Ygilany
Copy link

Ygilany commented May 23, 2023

@isalciuc renaming a collection is an adminCommand.

Here's an example for how you can do that

{
  "databaseChangeLog": [
    {
      "changeSet": {
        "id": "2023.05.22.1",
        "author": "Yahya Gilany",
        "comment": "Rename collections",
        "changes": [
          {
            "adminCommand": {
              "command": {
                "$rawJson": {
                  "renameCollection": "database-name.old-collection-name",
                  "to": "database-name.new-collection-name"
                }
              }
            }
          }
        ]
      }
    }
  ]
}

@isalciuc
Copy link
Author

isalciuc commented May 23, 2023

It fails with a not very informative NPE exception:

Caused by: java.lang.NullPointerException: null
at liquibase.ext.mongodb.statement.AdminCommandStatement.run(AdminCommandStatement.java:51)
at liquibase.ext.mongodb.statement.AbstractRunCommandStatement.execute(AbstractRunCommandStatement.java:51)
at liquibase.ext.mongodb.statement.AbstractRunCommandStatement.execute(AbstractRunCommandStatement.java:36)
at liquibase.nosql.executor.NoSqlExecutor.execute(NoSqlExecutor.java:187)

It also requires to run it as admin and to know the database name.

On the other hand, this command doesn't require to run as admin and to know the database name:

db.{source-collection-name}.renameCollection("{new-collection-name}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants