How to use Liquibase-MongoDb-Spring-boot

夙愿已清 提交于 2020-12-06 12:26:44

问题


I checked and found that liquibase is extended for Mongo DB but I cannot see any example of using it with spring-boot, can anyone suggest the way to use liquibase with spring-boot for mongodb. Any example would be helpful.


回答1:


I couldn't find any documentation on Liquibase support for MongoDB apart from this github repo: https://github.com/liquibase/liquibase-mongodb.

There is this one - mongock.io which is similar to how Liquibase work and can be easily integrated with Spring boot. Below is the github URL: https://github.com/cloudyrock/mongock




回答2:


Liquibase doesn't support MongoDB, but they provide an extension to support MongoDB. you can see more details here.
There are some prerequisite to be followed:-

  • At least using liquibase version 4.0.0 or latest one.
  • Add the mongo-java-driver dependency.
  • Add the Liquibase extension dependency.

Take into consideration, This way has a different syntax than we usually used with other DB like Postgres or SqlServer DBs.

<?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>


来源:https://stackoverflow.com/questions/64122133/how-to-use-liquibase-mongodb-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!