How to use Liquibase-MongoDb-Spring-boot

Viewed 5626

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.

3 Answers

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

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>

Suggest you to use NoSQL support data migration library such as mongock. It provide data migration most of time like liquibase. mongock provide migration class instead of liquibase XML or JSON.

Related