Skip to content


Subversion checkout URL

You can clone with
Download ZIP


mongoid & accessible_by #322

brewster1134 opened this Issue · 8 comments

3 participants


when accessing the accessible_by method on my models, a mongoid criteria object is returned with the following: selector: {"$or"=>[]},, which leads to the error $or requires nonempty array.

>> Product.count
=> 10
>> a
=> #<Ability:0x10501b3e0 @aliased_actions={:update=>[:edit], :create=>[:new], :read=>[:index, :show]}, @rules=[#<CanCan::Rule:0x10501b368 @match_all=false, @subjects=[:all], @conditions={}, @actions=[:manage], @expanded_actions=[:manage], @block=nil, @base_behavior=true>]>
>> Product.accessible_by(a)
=> #<Mongoid::Criteria
    selector: {"$or"=>[]},
    options:  {},
    class:    Product,
    embedded: false>
>> Product.accessible_by(a).first
Mongo::OperationFailure: $or requires nonempty array

do i need to pass conditions through accessible_by to make a proper mongo query?


You shouldn't need to pass anything more to accessible_by. Looks like this is a bug in the mongoid model. Thanks for reporting this. I'll look into fixing it. BTW, which version of mongoid and mongodb are you using?


oops meant to include that with my original post...
mongodb v1.6.6-pre- & mongoid gem 2.0.0.rc.8

i will be upgrading to 1.8 pretty soon and i will let you know if that fixes it.


I can verify that this behavior is present in mongodb 1.8.0 and mongoid 2.0.0.rc.8


@joshuabowers thanks for confirming, now time to research it.


fixing mongoid 'or' error - closed by e96cf5b

@ryanb ryanb closed this

I released a new version with this fix. Try 1.6.4 and see if it's working.


Seems to be working in my environment. Thanks Ryan!


working for me as well. now that is promptness!

@jhuckabee jhuckabee referenced this issue from a commit in jhuckabee/cancan
@ryanb fixing mongoid 'or' error - closes #322 e96cf5b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.