Reputation: 347
Been Googling around to try and find a solution to this problem, the main thing is that people are experiencing this error when setting up Mongoid with Devise.
However I'm not using devise, I'm using omniauth.
The error appears when I add this to my application_controller (PS: I'm not sure this code is even the best solution for Rails 4, I'm following Railscast 'Simple OmniAuth' tutorial.):
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_user
The full error reads:
The operation: #<Moped::Protocol::Query
@length=82
@request_id=6
@response_to=0
@op_code=2004
@flags=[]
@full_collection_name="mw_development.users"
@skip=0
@limit=0
@selector={"_id"=>{"$oid"=>BSON::ObjectId('54b13b4e536562107c000000')}}
@fields=nil>
failed with error 17287: "Can't canonicalize query: BadValue unknown operator: $oid"
does anyone know what's going on? I know one fix is to comment out the cookies_serializer.rb, but I don't like to comment out things I don't know what do, and I'm sure there is a better solution.
Upvotes: 0
Views: 277
Reputation: 11
I had the same problem.
You see, you cannot use BSON:: ObjectId just like that. Not sure why it so. (Let say it's magic.)
Try to convert it in string instead.
User.find(session[:user_id].to_s)
Or in some similar way. Hope it was helpful.
Upvotes: 1