liquibase-mongodb icon indicating copy to clipboard operation
liquibase-mongodb copied to clipboard

Support Updates to a collection

Open xendren opened this issue 2 years ago • 7 comments

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.

xendren avatar Sep 14 '22 14:09 xendren

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 avatar Sep 22 '22 11:09 Nida96

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

Nida96 avatar Sep 22 '22 20:09 Nida96

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>

DanZDatical avatar Sep 22 '22 22:09 DanZDatical

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

Nida96 avatar Oct 04 '22 09:10 Nida96

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.

DanZDatical avatar Oct 04 '22 15:10 DanZDatical

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

oliallan14 avatar Oct 04 '22 15:10 oliallan14

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.

xendren avatar Nov 16 '22 19:11 xendren