liquibase / liquibase-mongodb

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

Support Updates to a collection #290

Open xendren opened 2 years ago

xendren commented 2 years ago

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.

Nida96 commented 2 years ago

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?

Nida96 commented 2 years ago

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()

DanZDatical commented 2 years ago

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>
Nida96 commented 2 years ago

Any plan on providing support for this without runCommand() ?

DanZDatical commented 2 years ago

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.

oliallan14 commented 2 years ago

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

xendren commented 1 year ago

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.