Skip to content

Raw Mongo findOneAndUpdate cannot express returnDocument or sort — command AST supports them but RawMongoCollection does not expose them #927

Description

@nurul3101

Package and version

@prisma-next/mongo-orm (raw collection surface) @ 0.14.0 (repo main @ 284a838)

What happened?

The raw Mongo surface cannot express returnDocument or sort on findOneAndUpdate, even though the command AST supports both:

Practical consequence: with the driver defaulting to returnDocument: 'before', the standard atomic-counter idiom findOneAndUpdate(filter, { $inc: … }, { upsert: true }) returns an empty result on the first call (there is no "before" document), and there is no way to ask for the post-update document.

What did you expect to happen?

findOneAndUpdate on the raw collection accepts { upsert?, returnDocument?, sort? } and forwards them into RawFindOneAndUpdateCommand, matching what the AST already models.

Minimal reproduction

const result = await run(
  raw.collection('counters').findOneAndUpdate(
    { _id: 'orders' },
    { $inc: { seq: 1 } },
    { upsert: true }, // returnDocument / sort not expressible
  ),
);
// first call: [] — driver default returnDocument 'before' returns the (non-existent) pre-image

Reproduced against mongodb-memory-server in a local docs-validation harness.

Environment

  • Node: 24.x
  • OS: macOS 15 (Darwin 24.6.0)
  • Package manager: pnpm
  • Database: MongoDB via mongodb-memory-server

Additional context

The typed pipeline builder's findOneAndUpdate does expose returnDocument (defaulting to 'after'), so this gap is specific to the raw surface — and the raw surface is exactly where escape-hatch patterns like upsert counters live.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageAwaiting maintainer triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions