【问题标题】:How to use Liquibase-MongoDb-Spring-boot如何使用 Liquibase-MongoDb-Spring-boot
【发布时间】:2020-09-29 14:50:32
【问题描述】:
我检查并发现 liquibase 已针对 Mongo DB 进行了扩展,但我看不到任何将其与 spring-boot 一起使用的示例,任何人都可以建议将 liquibase 与 spring-boot 一起用于 mongodb 的方法。
任何示例都会有所帮助。
【问题讨论】:
标签:
mongodb
spring-boot
liquibase
【解决方案2】:
Liquibase doesn't support MongoDB,但是they provide an extension to support MongoDB.你可以看到更多细节here。
有一些先决条件:-
请注意,这种方式的语法与我们通常用于其他数据库(如 Postgres 或 SqlServer 数据库)的语法不同。
<?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>
【解决方案3】:
建议大家使用mongock等NoSQL支持的数据迁移库。它大部分时间都像 liquibase 一样提供数据迁移。 mongock 提供迁移类而不是 liquibase XML 或 JSON。