If a hash contains a string and a symbol in different keys which are equivalent, it appears that it's possible for both of these values to be inserted into the database.
This appears to be perfectly valid in the JSON spec:
http://www.ietf.org/rfc/rfc4627.txt
" The names within an object SHOULD be unique."
But, this creates buggy issues for database applications.
Here is a snippet of code which can be used to insert duplicate keys- with conflicting values- into a Mongo collection
#!/usr/bin/env ruby
require 'mongo'
DB = Mongo::MongoClient.new("localhost",27017).db("CR")
before = Hash.new
before['_id'] = 'duplicate_test'
before['i_am_a_key'] = 'am i evil?'
before[:i_am_a_key] = 'yes i am!'
DB['erase_me'].insert(before)
after = DB['erase_me'].find_one({_id:'duplicate_test'})
puts("before inserting: --> #
{before}")
puts("after inserting: --> #
")
Will generate:
before inserting: -->
after inserting: -->
{"_id"=>"duplicate_test", "i_am_a_key"=>"yes i am!"}This may seem expected, however if we perform a mongoexport:
/var/www/html/ted/steve/rubycode
{devel} 06:34 PM $ mongoexport -h localhost -d CR -c erase_me | grep "_id"
connected to: 172.16.10.55:27017,172.16.20.55:27017,172.16.20.56:27017
exported 1
It appears that identical keys exist with conflicting values.