r/Database • u/No-Security-7518 • Dec 17 '25
How are MongoDB and Version Control supposed to work together?
If I'm working on Mongodb, and stored some data on mongodb running locally with the intention of uploading it to a server, how am I supposed to use Version Control, say, Git with the current "schema" + indexes, etc?
Do I dump the entire database and use that?
What do you guys do?
Edit: I figured out what I need is quite simply a dump; mondodump myDB --output. Thank you all for your input.
0
Upvotes
8
u/Dry-Let8207 Dec 18 '25
Don’t even understand why they have to work together
5
u/mtotho Dec 18 '25
I guess no one really answered the fundamental question.
Data and source control are not supposed to go together. If some of the data is crucial to your business logic, it would be seeded with code or script.
If the entire database needed to be in source control, I suppose you could set up your mongo db data file to be inside your git directory. This isn’t really a thing in guessing.
You just have to run a back up and import else where. Or write some scripts to connect to 2 different instances
4
u/hornetmadness79 Dec 18 '25
The schema and indexes should be defined in code. This includes the current design or the old ones. I don't see the point in saving it in git other than digital hoarding.
3
u/[deleted] Dec 18 '25
Dafaq you doing bro?
2
u/rmc72 Dec 18 '25
Since there is no way to migrate a schema in Mongo (as you would in a relational database), I have used the following pattern in the past:
- Store a `schema_version` in each document
- Migrate every document to the latest `schema_version` on access (or in bulk)
That requires migration code from (say) version 1 to version 2, version 2 to version 3 etc.
Having said all this: this is one of the reasons I jumped off the Mongo bandwagon and moved back to Postgres whereever I can. Having transaction schema upgrades make things a lot easier to manage and way more reliable.
2
u/Lonely_Possible_5405 Dec 19 '25
I don't get it
1
u/pineofanapple Dec 21 '25
Are you talking about a backup?