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
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: