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

Can't canonicalize query: BadValue unknown operator: $oid

    • Type: Icon: Task Task
    • Resolution: Done
    • 5.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      Error appear when current_user is active.

      View (pages/index):

      <% if current_user %>
      Signed in as <%= current_user.name %>!
      <%= link_to 'Sign out', signout_path %>
      <% end %>

      Application controller:

      class ApplicationController < ActionController::Base

      1. Prevent CSRF attacks by raising an exception.
      2. For APIs, you may want to use :null_session instead.
        protect_from_forgery with: :exception

      private

      def current_user
      @current_user ||= User.find(session[:user_id]) if session[:user_id]
      end

      helper_method :current_user
      end

      User model:

      class User
      include Mongoid::Document
      include Mongoid::Timestamps

      field :provider, type: String
      field :uid, type: String
      field :name, type: String

      def self.from_omniauth(auth)
      where(auth.slice("provider", "uid")).first || create_from_omniauth(auth)
      end

      def self.create_from_omniauth(auth)
      create! do |user|
      user.provider = auth["provider"]
      user.uid = auth["uid"]
      user.name = auth["extra"]["raw_info"]["name"]
      end
      end
      end

      Error:

      The operation: #<Moped::Protocol::Query
      @length=90
      @request_id=19
      @response_to=0
      @op_code=2004
      @flags=[]
      @full_collection_name="monkeywork_development.users"
      @skip=0
      @limit=0
      @selector={"_id"=>{"$oid"=>BSON::ObjectId('54e5d31c5365623549000000')}}
      @fields=nil>
      failed with error 17287: "Can't canonicalize query: BadValue unknown operator: $oid"

            Assignee:
            Unassigned Unassigned
            Reporter:
            almnes almnes
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: