<p>= MongoDelegate</p> <p>A DelegateCollection wraps a local collection and remote collection in one object that implements the Collection interface.</p> <ul> <li>All reads are first done on the local collection, then supplemented by a read on the remote collection, if necessary.</li> <li>All write occur in the local collection. The remote collection is treated as read-only.</li> </ul> <p>This was inspired by things I’ve been told about Goldman Sachs’ proprietary object database. You can point one database at another remote database, and it will function in this manner.</p> <p>The classic use case is debugging a production problem, or developing while using production data.</p> <ul> <li>The annoying way: Generate data that mimics production, get a production dump and load it locally, or “test” in production while walking on eggshells to make sure not to break anything</li> <li>The easy way: Have your local app use a delegating collection that points at the production db. Your app will be using live production data, but all writes occur locally. As writes occur, the app will get your newly written data for those documents. Your app can be oblivious to the delegation and function normally, and you can modify data without fear.</li> </ul> <p>Just create a DelegatingDatabase and pass to your application, wherever you would normally supply a database<br />
db = Mongo::DelegatingDatabase.new(:local => Mongo::Connection.new.db(‘db-name’), :remote => Mongo::Connection.new(‘remote ip’).db(‘db-name’))<br />
<br />
Later, anywhere collections are retrieved in your app<br />
coll = db.collection(‘some-collection-name’) # This returns an instance of Mongo::DelegatingCollection</p>
<p>== Note on Patches/Pull Requests</p> <ul> <li>Fork the project.</li> <li>Make your feature addition or bug fix.</li> <li>Add tests for it. This is important so I don’t break it in a<br />
future version unintentionally.</li>
<li>Commit, do not mess with rakefile, version, or history.<br />
(if you want to have your own version, that is fine but<br />
bump version in a commit by itself I can ignore when I pull)</li>
<li>Send me a pull request. Bonus points for topic branches.</li> </ul> <p>== Copyright</p> <p>Copyright © 2010 Mike Harris. See <span class=“caps”>LICENSE</span> for details.</p>