Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-6337

Investigate changes in NODE-4855: Add static fromX bson type creation methods to Binary and ObjectId

    • Type: Icon: Investigation Investigation
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • No version
    • Affects Version/s: None
    • Component/s: None
    • Not Needed

      Request

      Add fromX methods to the Binary and ObjectId classes that provide bespoke translations from common serialized formats into the BSON types. These would be an alternative to the constructors which have some limitations or specific requirements for the myriad of inputs they support and remove some redundant translations required to use them.

      Motivations

      • Shell/Compass can print out easy to copy code that creates a Binary from one of these formats (currently users need to use Buffer to make bytes from base64)
      • Both BSON types are commonly used as primary keys on documents, ease of use with creation/copy+paste/translation to/from helps in many scenarios for query building or document creation

      AC

      (It may be desirable to break up the following into subtasks)

      Implementation requirements

      • ObjectId and Binary (and by inheritance UUID)
        • add static fromHex(hex: string) method that accepts a hex digits string to be turned into bytes before constructing the bson type
        • add static fromBase64(base64: string) method that accepts a base64 string to be turned into bytes before constructing the bson type
        • add static fromBytes(bytes: Uint8Array | AnyArrayBuffer, byteOffset?, byteLength?) that accepts a Uint8Array (or subclass, ex. Node.js buffer) or a (Shared)ArrayBuffer and applies offset and length before constructing the bson type

      Testing requirements

      • Test various inputs within and out of bounds of the what the methods support
      • TBD

            Assignee:
            Unassigned Unassigned
            Reporter:
            dbeng-pm-bot PM Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: