Skip to main content

Update Single Document

PATCH 

/collections/:collectionName/documents/:docId

Update a single document by its _id. Supports all update operators ($set, $inc, $push, etc.). Use returnDoc=true to return the updated document. Returns 404 if the document does not exist and upsert=false.

Request

Path Parameters

    collectionName stringrequired

    Collection name

    docId stringrequired

    Document ID (supports both ObjectId strings and plain strings)

Body

required
    data objectrequired

    Update data (EJSON object), supports update operators

    replaceMode boolean

    Whether to replace the entire document

    upsert boolean

    Whether to create if not exists

    returnDoc boolean

    Whether to return the updated document

    transactionId string

    Transaction ID

Responses

Update successful

Schema
    updated integer

    Number of updated documents

    matched integer

    Number of matched documents

    upsert_id string

    ID of the upserted document (if any)

    doc object

    Updated document (only returned when returnDoc=true)

Loading...