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

BSON::OrderedHash#reject does not work like Hash#reject

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.0.8
    • Affects Version/s: 1.0.7
    • Component/s: None
    • Labels:
      None
    • Environment:
      mongodb 1.6.1
      mongo 1.0.7
      bson/bson_ext 1.04

      BSON::OrderedHash#reject is not working like ruby's Hash#reject.

      ruby methods destroys the key in the returned hash. Mongo's just set the value to nil

      Here is an irb session demonstration both behaviours.

      irb(main):017:0> h=

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

      =>

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

      irb(main):018:0> coll= Mongo::Connection.new.db("test").collection("test")
      => #<Mongo::Collection:0xb744a630 @connection=#<Mongo::Connection:0xb745e144 @options={}, @logger=nil, @queue=#<ConditionVariable:0xb745ca38>, @nodes=[["localhost", 27017], ["zeta_tablet_nux", 27017], ["zeta_tablet_nux", 27018]], @nodes_tried=[["localhost", 27017]], @sockets=[], @size=1, @host="localhost", @slave_ok=nil, @auths=[], @safe_mutexes=

      {#<TCPSocket:0xb745c5b0>=>#<Mutex:0xb745a5e4>}

      , @id_lock=#<Mutex:0xb745d0dc>, @connection_mutex=#<Mutex:0xb745ca88>, @checked_out=[], @timeout=5.0, @port=27017>, @name="test", @db=#<Mongo::DB:0xb744a9a0 @connection=#<Mongo::Connection:0xb745e144 @options={}, @logger=nil, @queue=#<ConditionVariable:0xb745ca38>, @nodes=[["localhost", 27017], ["zeta_tablet_nux", 27017], ["zeta_tablet_nux", 27018]], @nodes_tried=[["localhost", 27017]], @sockets=[], @size=1, @host="localhost", @slave_ok=nil, @auths=[], @safe_mutexes=

      {#<TCPSocket:0xb745c5b0>=>#<Mutex:0xb745a5e4>}

      , @id_lock=#<Mutex:0xb745d0dc>, @connection_mutex=#<Mutex:0xb745ca88>, @checked_out=[], @timeout=5.0, @port=27017>, @name="test", @strict=nil, @pk_factory=nil>, @hint=nil, @pk_factory=BSON::ObjectID>
      irb(main):019:0> coll.find_one
      => nil
      irb(main):020:0> coll.insert(h)
      => BSON::ObjectID('4c6e80e701ebbf358d000003')
      irb(main):021:0> coll.find_one
      =>

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

      irb(main):022:0> Mongo::Connection.new.db("test").collection("test").find_one.reject

      {|k,v| k=='c'}
      => {"_id"=>BSON::ObjectID('4c6e80e701ebbf358d000003'), "a"=>"b", "c"=>nil}
      irb(main):023:0> Mongo::Connection.new.db("test").collection("test").find_one.delete_if{|k,v| k=='c'}

      =>

      {"_id"=>BSON::ObjectID('4c6e80e701ebbf358d000003'), "a"=>"b"}

      irb(main):024:0> h.reject

      {|k,v| k=='c'}
      => {"a"=>"b", :_id=>BSON::ObjectID('4c6e80e701ebbf358d000003')}
      irb(main):025:0> h.delete_if{|k,v| k=='c'}

      =>

      {"a"=>"b", :_id=>BSON::ObjectID('4c6e80e701ebbf358d000003')}

            Assignee:
            kbanker Kyle Banker
            Reporter:
            zeta Benoit Larroque
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: