BSON::Document#to_hash should be defined so that Hash(doc) works

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Won't Do
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Ruby Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Currently BSON::Document behaves as follows:

      doc = BSON::Document.new({"foo" => "bar"})
      
      doc.to_h.class #=> Hash -- CORRECT
      
      Hash(doc).class #=> BSON::Document -- non-optimal / confusing

      Defining `BSON::Document#to_hash` as an alias to `.to_h` would fix this. Since the content of BSON::Document is 1-to-1 equivalent to a hash, it makes sense to do.

      Compare for reference the equivalent method `BSON::ObjectId#to_str` which enables us to do:

      String(BSON::ObjectId.new).class #=> String

      (For clarity, this is only for BSON::Document, am NOT proposing the same for Mongoid::Document)

            Assignee:
            Unassigned
            Reporter:
            Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: