-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
Affects Version/s: 1.0.7
-
Component/s: None
-
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=
, @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
=>
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')}