MongoDB backup as text rather than binary for source control

前端 未结 1 992
伪装坚强ぢ
伪装坚强ぢ 2020-12-21 03:17

Is it possible to do this?

The reason I ask is that it would seem useful to perform a backup as a pre-commit hook, and include that text-based backup somehow with th

相关标签:
1条回答
  • 2020-12-21 04:12

    MongoDB stores its data in a BSON (Binary JSON) format so if you are converting to a text-only format you should be aware of potential data type fidelity issues. If you want a consistent backup of your MongoDB database, the recommended format would be the binary output of mongodump. I wouldn't recommend bloating your git repo with binary DB backups, though.

    Typically one of the liberating aspects of a database with schema flexibility is not having to worry about schema migrations during development. This does require some consideration on how your application will handle varying schema versions, so having a more controlled approach is fine, too.

    Since your main goal is to keep your database schema in sync with code changes, a much better approach would be to investigate schema migration tools. These typically allow you to create upgrade/downgrade code snippets with a defined order of application to a database, and ensure that any changes to the database schema that aren't handled by your application code are captured in the migration scripts.

    Some example tools:

    • mongo-migrate (NodeJS)
    • Mongeez (Java)
    0 讨论(0)
提交回复
热议问题