liquibase / liquibase-mongodb

MongoDB extension for Liquibase
Apache License 2.0
54 stars 46 forks source link

Adds support for updateMany changes #574

Open lewishazell opened 1 month ago

lewishazell commented 1 month ago

Hey!

I really wanted to see this feature when using the extension and I could see it was requested a while ago in #449. While running update through runCommand is an option, it's harder to discern exactly what is happening.

This change adds mongodb:updateMany as a change type which takes a filter and update.

For example,

<mongodb:runCommand>
    <mongodb:command>
        {
            update: "atmosphericData",
            updates: [{
                q: { },
                u: [{ 
                    $set: { 
                        temperature: {
                            $replaceAll: {
                                input: "$temperature",
                                find: "c",
                                replacement: "C"
                            }
                        }
                    }
                }]
            }]}
    </mongodb:command>
</mongodb:runCommand>

Can now be expressed as

<mongodb:updateMany collectionName="atmosphericData">
    <mongodb:filter>
        { }
    </mongodb:filter>
    <mongodb:update>
        [{ 
            $set: { 
                temperature: {
                    $replaceAll: {
                        input: "$temperature",
                        find: "c",
                        replacement: "C"
                    }
                }
            }
        }]
    </mongodb:update>
</mongodb:updateMany>

Tests for both UpdateManyChange and the existing UpdateManyStatement are included.