DEV Community

Roman Mikhailov
Roman Mikhailov

Posted on

1

MongoDb migration frameworks

What do you do when you need to upgrade/downgrade schema and seed on first install your MongoDB?

I'm looking for opinions, examples, tutorials, and suggestions from the community.

Here's an example of one using node-migrate

https://www.freecodecamp.org/news/how-to-automate-database-migrations-in-mongodb-d6b68efe084e/

Background:

I have a Micro Services (5) application that uses MongoDd. I'd like to allow my services to upgrade their schema in an automated way. In other words, I'd like to avoid running scripts or queries manually. If I have to downgrade a version of a service, it should be able to downgrade the schema as well. It's also possible that a service is scaled horizontally, more than one clone is running. Therefore, this solution must avoid collusion or duplication. Two or more clones should not attempt to apply a migration at the same time.

I'm leaning towards using node-migrate to implement the migration steps. What to do about the control of race conditions is not clear yet for me. I'm thinking about putting the database in read-only mode for the duration of the upgrade. I realized that this last statement does not make sense. I would never roll out all instances at once. It would always be one at a time. Therefore, the first one to get a new version will take care of the upgrade.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay