deploy_mongo is db deploy tool for mongodb.
gem install deploy_mongo
deploy_mongo 'path/to/mongodb.yml' [rollback:(1|2|3|..|all)]
- rollback:all
-
rollbacks all the deltas
-
deploy_mongo/spec/mongodb.yml for mongodb.yml config file
-
deploy_mongo/spec/integration/deltas for delta files
-
hostname: mongodb database server hostname>
-
port: mongodb server port number , by default 27017
-
delta_path: path/to/deltas folder relative to mongodb.yml
-
database: <couchdb database name>
-
mongo_shell_path: full path to mongo shell (can be found in mongodb install folder/bin
<Delta Number>_<Description>.js example :- 1_add_address_to_customer.js 2_add_phone_to_customer.js 11_update_phone_with_std_codes.js 12_delete_customer_with_name_equal_to_name_1.js 13_copy_and_create_new_customer.js
<java script command used to modify database> //@undo <java script rollback command used when rolling back applied delta.>
db.customer.update({},{$set: {"address": "some address" } } , false , true ); //@undo db.customer.update({},{$unset: {"address": 1}},false,true);
db.customer.update({},{$set: {"phone": "897907979" } } , false , true ) //@undo db.customer.update({},{$unset: {"phone": 1}},false,true)
Example for creating new document after copying details from another customer (13_copy_and_create_new_customer.js)¶ ↑
db.customer.find({ "name" : "name_2" }).forEach(create_customer); function create_customer(doc){ delete doc._id; doc.name = "new name"; db.customer.save(doc); } //@undo db.customer.remove({"name" : "new name"})
db.customer.remove({ "name" : "name_1" }); //@undo db.customer.save({"name" : "name_1", "address" : "some address" , "phone" : "+9168687868" });