Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-265

BSON::OrderedHash#reject! leaves keys with nil values

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.3.1
    • Affects Version/s: 1.3.0
    • Component/s: None
    • Labels:
      None

      ree-1.8.7-2010.02 > coll= Mongo::Connection.new.db("test").collection("test")
      => #<Mongo::Collection:0x1067975c8 @hint=nil, @cache_time=300, @cache={}, @connection=#<Mongo::Connection:0x1067a7018 @id_lock=#<Mutex:0x1067a6b90>, @queue=#<ConditionVariable:0x1067a6af0>, @timeout=5.0, @host_to_try=["localhost", 27017], @primary_pool=#<Mongo::Pool:0x10679f840 @checked_out=[], @queue=#<ConditionVariable:0x10679f0e8>, @timeout=5.0, @size=1, @pids=

      {#<TCPSocket:0x10679a6d8>=>5914}

      , @connection_mutex=#<Mutex:0x10679f110>, @port=27017, @sockets=[#<TCPSocket:0x10679a6d8>], @connection=#<Mongo::Connection:0x1067a7018 ...>, @host="localhost", @socket_ops=

      {#<TCPSocket:0x10679a6d8>=>[]}

      >, @connection_mutex=#<Mutex:0x1067a6b68>, @op_timeout=nil, @port=nil, @logger=nil, @safe_mutexes=

      {#<TCPSocket:0x10679a6d8>=>#<Mutex:0x10679a458>, #<TCPSocket:0x1067a69d8>=>#<Mutex:0x1067a0bc8>}

      , @slave_ok=nil, @read_primary=true, @safe=false, @pool_size=1, @auths=[], @host=nil, @primary=["localhost", 27017]>, @db=#<Mongo::DB:0x1067981d0 @strict=nil, @cache_time=300, @connection=#<Mongo::Connection:0x1067a7018 @id_lock=#<Mutex:0x1067a6b90>, @queue=#<ConditionVariable:0x1067a6af0>, @timeout=5.0, @host_to_try=["localhost", 27017], @primary_pool=#<Mongo::Pool:0x10679f840 @checked_out=[], @queue=#<ConditionVariable:0x10679f0e8>, @timeout=5.0, @size=1, @pids=

      {#<TCPSocket:0x10679a6d8>=>5914}

      , @connection_mutex=#<Mutex:0x10679f110>, @port=27017, @sockets=[#<TCPSocket:0x10679a6d8>], @connection=#<Mongo::Connection:0x1067a7018 ...>, @host="localhost", @socket_ops=

      {#<TCPSocket:0x10679a6d8>=>[]}

      >, @connection_mutex=#<Mutex:0x1067a6b68>, @op_timeout=nil, @port=nil, @logger=nil, @safe_mutexes=

      {#<TCPSocket:0x10679a6d8>=>#<Mutex:0x10679a458>, #<TCPSocket:0x1067a69d8>=>#<Mutex:0x1067a0bc8>}

      , @slave_ok=nil, @read_primary=true, @safe=false, @pool_size=1, @auths=[], @host=nil, @primary=["localhost", 27017]>, @safe=false, @name="test", @pk_factory=nil>, @safe=false, @name="test", @pk_factory=BSON::ObjectId>
      ree-1.8.7-2010.02 > h=

      {'a' => 'b','c' => 'd'}


      =>

      {"a"=>"b", "c"=>"d"}


      ree-1.8.7-2010.02 > coll.insert(h)
      => BSON::ObjectId('4da86d5811a03c171a000001')
      ree-1.8.7-2010.02 > coll.find_one
      =>

      {"_id"=>BSON::ObjectId('4da86d5811a03c171a000001'), "a"=>"b", "c"=>"d"}


      ree-1.8.7-2010.02 > result = coll.find_one
      =>

      {"_id"=>BSON::ObjectId('4da86d5811a03c171a000001'), "a"=>"b", "c"=>"d"}


      ree-1.8.7-2010.02 > result.reject!

      { |key, value| key == 'a' }
      => {"_id"=>BSON::ObjectId('4da86d5811a03c171a000001'), "a"=>nil, "c"=>"d"}


      Versus:


      ~ $ irb
      >> a = { 'a' => 1, 'b' => 2 }
      => {"a"=>1, "b"=>2}
      >> a.reject! { |key, value| key == 'a' }

      =>

      {"b"=>2}

      >>

      I've worked around this by using BSON::OrderedHash#delete_if

            Assignee:
            kbanker Kyle Banker
            Reporter:
            bpoweski Ben Poweski
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: