AQS
AQS

Reputation: 1

Can we use mongock as a migration tool to rename mongodb collection

We are going to rename a mongodb collection and writing migration script in our spring boot microservice.Is it ok to use mongock for the same? Trying to understand if the changeunit is executed once on app startup, would it throw exception once it is restarted and does not find the old collection to be renamed.

mongoTemplate.getCollection("collection1").rename("collection2");

On first execution it will be renamed but what about second time the application is deployed.

Upvotes: 0

Views: 705

Answers (1)

Ilan Toren
Ilan Toren

Reputation: 60

Aggregation stage $out A simple way to copy a collection is the aggregation stage $out

db.collectionOld.aggregate( [{$out: "collectionNew"}])

followed by a drop of the old collection (do yourself a favor and backup that collection prior to the drop) The two steps can be combined (but not the backup) into a simple program or better scripted in bsh or such.

Upvotes: 0

Related Questions