Skip to content

Mongo Binary fields lose their BSON subtype on a read and write back #30459

Open

Description

@wmadden-electric

What a user sees. A MongoDB Binary field (mongo/binary@1) reads any stored BSON Binary as a plain Uint8Array and writes every Uint8Array as subtype 0. A document that stored a UUID (subtype 4), an MD5 (subtype 5) or a user-defined subtype comes back without its subtype, and writing the value back through the ORM stores it as subtype 0. The bytes survive; the subtype does not. Collections created by Prisma 6 or by other drivers can hold such values, and the Prisma 6 MongoDB schema reader maps Prisma 6 Bytes to this codec.

Where. binaryEncode and binaryDecode in packages/3-mongo-target/1-mongo-target/src/core/bson-scalar-helpers.ts (new Binary(value) on write, wire.value() on read).

Likely fix. Decide the rule and make it explicit. Two options: refuse a stored Binary whose subtype is not 0 or 2 on decode, naming the field, so nothing is silently rewritten; or add a codec (or a parameter on Binary) that keeps the subtype, and point users with UUID data at it. Users who need every subtype preserved today can type the field Bson, which returns the driver's Binary with its subtype.

Where it came from. Recorded when the Binary codec was added in #30396; relevant to the Prisma 6 reader in #30405.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions