Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having an issue using mongoid_auto_inc with Mongoid 3.0.0.rc #9

Open
sawilde opened this issue Jul 17, 2012 · 1 comment
Open

Having an issue using mongoid_auto_inc with Mongoid 3.0.0.rc #9

sawilde opened this issue Jul 17, 2012 · 1 comment

Comments

@sawilde
Copy link

sawilde commented Jul 17, 2012

I get undefined method 'database' for Mongoid::Module

I ended up monkey patching the code such that the if ::Mongoid::VERSION < '3' statements are no longer required i.e. I know I only want to execute the other branches

module MongoidAutoInc

  class Incrementor
    class Sequence
      def collection
        Mongoid.default_session[@collection]
      end

      def update_number_with(mongo_func)
        opts = {
            "query"  => query,
            "update" => mongo_func,
            "new"    => true # return the modified document
        }
        collection.database.command({findandmodify: collection.name}.merge(opts))['value']['number']
      end
    end
  end
end

NOTE: ::Mongoid::VERSION is returning 3.0.0.rc (alas I can't upgrade to latest Mongoid as the latest Moped requires Ruby 1.9.3 and I stuck on 1.9.2 for now)

@rdetert
Copy link

rdetert commented Apr 29, 2013

I was still having trouble so I had to use a forked gem. Place this in your Gemfile

gem 'mongoid_auto_increment', :git => 'git://github.com/teriyakisan/mongoid_auto_increment.git'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants