Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-577

Add struct tags to choose BSON types

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • 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?

      The new bsoncodec package handles encoding and decoding of known types, but it doesn't handle encoding known types to their non-default BSON types. For instance, while decoding into an int64 for a DateTime type could be supported, there wouldn't be a way to properly encode the int64 to a DateTime BSON type. This violates the ability to round trip types in the BSON library and it causes information loss by default. For this reason, the BSON decoders do not currently support decoding a DateTime into an int64. Users who need this functionality required to register custom codecs to handle this case, or to handle BSON marshaling on their own.

       

      A better solution is to allow users to tag their struct values with a bsontype struct field. This would allow the user to pass information to the encoders and decoders so they can properly handle round trip enabled encoding and decoding without information loss for non standard BSON types. This would enable users to encode a string to essentially any BSON type and also decode it. This is especially useful for ObjectIDs and date time strings.

            Assignee:
            Unassigned Unassigned
            Reporter:
            kris.brandow@mongodb.com Kristofer Brandow (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: