如何使用Liquibase-MongoDb-Spring-boot

问题描述

我检查发现liquibase已扩展到Mongo DB,但我看不到任何将spring-boot与{{1}一起使用的示例,有人能建议将liquibase与{{1 }} spring-boot。 任何示例都将有所帮助。

解决方法

除了这个github回购之外,我找不到关于MongoDB的Liquibase支持的任何文档:https://github.com/liquibase/liquibase-mongodb

有一个-mongock.io,类似于Liquibase的工作方式,可以轻松地与Spring boot集成。以下是github URL: https://github.com/cloudyrock/mongock

,

建议您使用NoSQL支持的数据迁移库,例如mongock。它像 liquibase 一样在大多数情况下提供数据迁移。 mongock 提供迁移类而不是 liquibase XML 或 JSON。

,

Liquibase doesn't support MongoDB,但是they provide an extension to support MongoDB.您可以看到更多详细信息here
必须满足一些先决条件:-

请注意,这种方式的语法不同于我们通常与其他数据库(如Postgres或SqlServer DB)一起使用的语法。

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd
      http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

<changeSet id="1" author="bob">
    <ext:createCollection collectionName="myCollection">
        <ext:options>
        {
        validator: {
            $jsonSchema: {
                bsonType: "object",required: ["name","address"],properties: {
                    name: {
                    bsonType: "string",description: "The Name"
                    },address: {
                bsonType: "string",description: "The Address"
                        }
                    }
                }
            },validationAction: "warn",validationLevel: "strict"
            }
            </ext:options>
        </ext:createCollection>
    </changeSet>
</databaseChangeLog>