
Ask HN: How do you handle mongodb migrations? - uptownhr
So you wrote your app with mongodb and went live. Maybe some small changes to db structure aren&#x27;t that big of a deal but eventually, you need to migrate data.<p>How have you guys been handling migrations in mongo?
======
jwilliams
For really deep, structural (and large datasets), then it's pretty difficult
to avoid downtime.

That said, those circumstances are hopefully pretty rare. We generally write
scripts that bridge between the two formats. One to copy/transform and one to
cleanup after. Run the transform, test and verify, then move to cleanup.

It's a huge pain, but if you keep on top of if --especially the cleanup-- then
it gets easier. It tends to get really hard once you get a lot of cruft. You
end up with the code vs data dichotomy. So keeping on top of that really helps
longer term.

~~~
uptownhr
How did you go about setting this up? Your own framework or any solutions out
there?

------
CerealBoy
It's been a while since I've played with mongo, but you could run an out-of-
band task to run through all existing data, transform, then push into a new DB
/ instance.

Your existing server would continue, you have a new endpoint to test with
updated application code, deployment can then be a standard blue-green
approach.

------
pryelluw
When you say migrate, what do you mean exactly?

~~~
uptownhr
Like a migrate in rdb, with mysql postgres. Something that keeps track and
makes DB schema changes.

------
nik736
"So you wrote your app with mongodb and went live."

No.

~~~
scalesolved
I don't think is the sort of posting we want on hackernews, either provide
some context or advice for the OP as this is not helpful and doesn't
contribute anything.

