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

{"$oid"=>"53adc74563616ef6e2290000"} query should work

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

      BSON::ObjectId.as_json returns a {{

      {"$oid"=>"...."}}}, So when querying, we should accept queries like:
      User.find({"$oid"=>"53adc74563616ef6e2290000"})
      # and
      User.where({"_id" => {"$oid"=>"53adc74563616ef6e2290000"} })
      


      This would solve a lot of serialization issues, where user._id.to_json is called to serialize the user, and afterwards some other process try to query using that id, which is a {{{"$oid"=>"...."}

      }}.

      That might be moped responsibility instead of Mongoid. Maybe, the main mongodb ruby driver should follow this pattern too.

      WDYT durran @estolfo

      [related https://github.com/plataformatec/devise/pull/2882]
      [related https://github.com/mongoid/mongoid/issues/3702]

      Besides this change, for Mongoid 4.1.x , to_key method, should not return a BSON::ObjectId, and it should return a string instead. As the to_key AM api is used mainly to serialize ids, which are suppose to be int or strings.

            Assignee:
            Unassigned Unassigned
            Reporter:
            arthurnn Arthur Nogueira Neves
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: