question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MongoDB: (Data) Migration Support

See original GitHub issue

Problem

Migrating your database over time is an important part of the development cycle. We offer some great tooling for SQL databases like Postgres and MySQL with prisma migrate and db push, but we don’t offer the same level of support for MongoDB.

There are a couple ways to migrate data with MongoDB:

  • On-Demand: When you add a new field to your schema, the past data isn’t touched. But when you go and read the collection, the collection is adjusted, so when you write the data back, your data now matches your schema.

    • This is how ORMs like Mongoose work
  • No Breaking Change Policy

    • Don’t rename or delete fields, only add fields.
    • Typically these teams are very well aware of using MongoDB and it’s constraints. They may have checks in CI/CD to make sure they don’t have backwards-incompatible changes to the schema
  • All-at-Once: where you update your schema and your past data to match your new schema all at once

    • This is a requirement of relational databases that all the data must match a specific schema, but not for NoSQL
    • All at once is what you think of when you think of traditional migration systems.

Suggested solution

  • We help you add, change and remove indexes
  • We offer some way to migrate old data to a new schema. The All-at-Once Migration above.

Alternatives

We currently support On-Demand and No Breaking Change Policy migrations.

For All-at-Once Migrations you’d need to write a script that transforms your data.

References

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
arthurfiorettecommented, May 16, 2022

Did anything came up about this topic? It would be awesome to prisma have a good integration with migrations.

For those looking for solutions, I’m using mongo-migrate-ts while prisma doesn’t add it.

3reactions
tomhoulecommented, Oct 31, 2021

@ajcwebdev there are currently no plans for migrations, because we haven’t seen a clear good solution yet. We’re going to merge and release https://github.com/prisma/prisma-engines/pull/2287 very soon though. The scope is only reflecting @@index and @@unique declarations in the prisma schema into MongoDB indexes with db push.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using MongoDB as a source for AWS DMS
Data migration that uses MongoDB as a source for AWS DMS supports most MongoDB data types. In the following table, you can find...
Read more >
Migrate To MongoDB Atlas
The Live Migration Service is a free service that we host and operate to make it simple to migrate your database to MongoDB...
Read more >
Migration To MongoDB Atlas
What sort of help can I get with migrations? What are the easy and the hard parts of a MongoDB Atlas migration? The...
Read more >
MongoDB Relational Migrator
Based on the schema mapping, move data into a target MongoDB cluster. Relational Migrator will support both Snapshot (one-time) and continuous data migration....
Read more >
Migrate or Import Data — MongoDB Atlas
You can bring data from existing MongoDB deployments, JSON , or CSV files into deployments in Atlas using either: live migration where Atlas...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found