Skip to content

Instantly share code, notes, and snippets.

@joeyAghion
Last active April 8, 2018 02:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joeyAghion/9955727 to your computer and use it in GitHub Desktop.
Save joeyAghion/9955727 to your computer and use it in GitHub Desktop.
class ImportBase
include Mongoid::Document
include Mongoid::Timestamps
field :import_version, type: String, default: 'v1' # legacy imports use 'v1' connection
before_create do
self.import_version = 'v2' # new imports use 'v2' connection
end
protected
def choose_connection
if import_version == 'v2'
Mongoid.session('imports') # alternate database configuration
else
self.class.mongo_session
end
end
end
class FooImport < ImportBase
def insert_data
# use choose_connection to insert data...
end
def get_data
# use choose_connection to retrieve data...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment