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

Support the BSON Symbol type



    • Type: New Feature
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: 12_01_17
    • Component/s: None
    • Labels:
    • Backwards Compatibility:
      Minor Change


      I happened to be perusing the BSON spec (http://bsonspec.org) and saw this:

      element ::= [ ... ]

      "\x0E" e_name string Symbol

      The mouseover tip says: "SYMBOL: Similar to a string but for languages with a distinct symbol type."

      The Ruby driver does not implement the Symbol type in any way distinct from String. If you save a document {:foo => "bar"} to Mongo and then query it again, you'll get back

      {"foo" => "bar"}


      Given how fundamental symbols are as hash keys in idiomatic Ruby, it would be a very positive step forward for code convenience and a more transparent persistence layer if symbols could be saved to MongoDB as symbols.

      This change should not have much negative impact on existing applications, because code that's been translating symbols to strings this entire time will continue to do so. Only code that's reliant on inconsistency (i.e., that puts symbols in and explicitly relies on strings back out) would be fragile. Given that the symbol-to-string mapping is not documented in the API, I consider that to be relying on a bug.




            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: