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 the code being committed, such that every revision in source control (git) has the necessary backups associated with it.
I realise that it may be possible to get MongoDB to spit out all it's collections as JSON, and back them up that way, but then this would not contain DB and collection metadata.
The central concern is that when branching to make changes to server side code, then reverting that branch, it is easy for us to forget to make the necessary backups that will allow an effective revert (code will no longer match schema). One could claim this is programmer error, but I think there should be some automation in place to ensure that we have a version of the database that is current for every version of the code. This is the problem with schemas that are amorphous during the early days of a project... dynamic schemas being Mongo's main blessing and curse.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…