Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4855

Add static fromX bson type creation methods to Binary and ObjectId

    • 3
    • Needed
    • Not Needed
    • 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?

      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 Follow up in comments.
      • Binary versions of the above methods must accept an optional subType: number argument.
        • add UUID overloads that return UUID instance

      Testing requirements

      • Test various inputs within and out of bounds of the what the methods support
      • Make sure uuids constructs as expected - pay attention to uuid v4 restriction that is planned to be removed

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Bailey Pearson, Warren James
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: