You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Liquibase MongoDB扩展删除索引?

Liquibase MongoDB 扩展删除索引的实现示例

目前官方提供的示例集中确实缺少删除索引的相关用例,这里提供两种可行的实现方式:

方式一:使用dropIndex专用变更类型

这是Liquibase MongoDB扩展原生支持的变更操作,写法更直观:

XML格式

<changeSet id="drop_user_email_index" author="your-username">
    <ext:dropIndex 
        collectionName="users" 
        indexName="email_1" 
        dbName="your-db-name"/>
</changeSet>

YAML格式

databaseChangeLog:
  - changeSet:
      id: drop_user_email_index
      author: your-username
      changes:
        - ext:dropIndex:
            collectionName: users
            indexName: email_1
            dbName: your-db-name

方式二:通过runCommand执行MongoDB原生命令

如果需要更灵活的操作(比如批量删除索引),可以直接调用MongoDB的dropIndexes命令:

XML格式

<changeSet id="drop_multiple_indexes" author="your-username">
    <ext:runCommand>
        <command>{ "dropIndexes": "users", "index": "*" }</command>
    </ext:runCommand>
</changeSet>

YAML格式

databaseChangeLog:
  - changeSet:
      id: drop_multiple_indexes
      author: your-username
      changes:
        - ext:runCommand:
            command: '{ "dropIndexes": "users", "index": "*" }'

说明:index字段设为"*"时会删除目标集合中除_id外的所有索引;如果要删除特定索引,替换为对应索引名称即可。

内容的提问来源于stack exchange,提问作者Douglas Santos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 03:20:59