Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1004

Runtime dynamic databases

      With a simple change to Mongoid::Collection I've been able to dynamically change the database at runtime. The change is in the master method of collection so it now looks like this (all other methods removed of course):

      module Mongoid
      class Collection
      def master(options = {})
      options.delete(:cache)
      db = Mongoid.databases[@klass.database] || Mongoid.master
      @master = (@master.nil? || db.name!=@master.db.name) ? Collections::Master.new(db, @name) : @master
      end
      end
      end

      instead of this:

      module Mongoid
      class Collection
      def master(options = {})
      options.delete(:cache)
      db = Mongoid.databases[@klass.database] || Mongoid.master
      @master ||= Collections::Master.new(db, @name)
      end
      end
      end

      Unfortunately the specs in collection_spec fail after this change and I haven't figured out a good way to make them pass without uglifying the specs. I don't really think this poses any problem but are rather things to do with mocks and expectations. Putting out there to get some feedback since I'm not that familiar with the mongoid codebase.

            Assignee:
            Unassigned Unassigned
            Reporter:
            johnae John Axel Eriksson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: