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

Support the BSON Symbol type

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • 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.

            Assignee:
            kbanker Kyle Banker
            Reporter:
            sfeley Stephen Eley
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: