Skip to content

Mongo ORM: upsert treats an existing document holding only the filter's fields as an insert #30516

Open

Description

@wmadden-electric

What a user sees. An upsert whose create sets a field that has an update default runs as one pipeline command that decides between insert and update by checking whether the matched document holds more than the filter's equality fields. If a document already exists whose only fields are the filter's fields (for example written by another tool), the ORM treats it as newly inserted: it writes the create values and skips the update default. Documents the ORM wrote always carry more fields, so ORM-only data is not affected.

Likely fix. Distinguish insert from update by a marker the server sets only on insert (for example compare $$ROOT against a $setOnInsert-only sentinel removed in the same pipeline), or document the limit next to upsert.

Found by review of the fixes for the Mongo defaults, codecs and Prisma 6 source project's manual QA.

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