Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.