Skip to content

Conversation

lewishazell
Copy link

@lewishazell lewishazell commented Oct 21, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant