liquibase-mongodb
liquibase-mongodb copied to clipboard
Support Updates to a collection
It appears that the extension is missing the ability to update a collection. How is everyone else on the planet solving the absence of updates while still using Liquibase for automated mongoldb deployments? This is to be a huge feature missing from the extension.
Completely agree, can we have an update on when can we expect this functionality or if there is any workaround for this at the moment?
Just like we have examples for insertOne() and insertMany() https://docs.liquibase.com/install/tutorials/mongodb.html. There should be methods to support updateMany() and updateOne()
While there is not a bespoke change type for updates, you can do updates by leveraging the runCommand change type in a changeset. It follows the pattern from Mongo's runCommand() function, so for update
, the example here: https://www.mongodb.com/docs/manual/reference/command/update/
For example:
<changeSet id="findAndModify_car2" author="someone">
<ext:runCommand>
<ext:command>
{
findAndModify: "car",
query: { name: "Honda", color: "Silver", cno:"H415" ,speed: 25 },
sort: { cno: 1 },
update: { $inc: { speed: 20 } },
upsert: true,
new: true
}
</ext:command>
</ext:runCommand>
<rollback>
<ext:runCommand>
<ext:command>
{
delete: "car",
deletes: [ {
q: { name: "Honda" },
limit: 0
}
]
}
</ext:command>
</ext:runCommand>
</rollback>
</changeSet>
Any plan on providing support for this without runCommand() ?
We are planning that plan right now and looking at different ways to do that.
How do you envision an instruction such as this being handled? For example, would it be better to have the ability to "Do it the same as in Compass or mongosh" or "Do it with a specialized Liquibase Changetype"?
We would love to hear your thoughts.
You can do most of what is needed with runCommand or adminCommand. These make the specific operators such as insertMany() redundant.
However, similar to plain SQL changes for relational systems (https://www.liquibase.com/blog/plain-sql) it could be neat to have plain-MQL feature added
I am not seeing the value of using Liquibase for MongoDB if I have to build my own update solution around the runCommand. For consistency, I would just build my solution to use the runCommand for all activities. The only thing I would be missing is the change log management that Liquibase provides, but that is all arbitrary in this context.