跳到主要内容

更新单个文档

PATCH 

/collections/:collectionName/documents/:docId

根据文档 _id 更新单个文档。支持所有更新操作符($set$inc$push 等)。 使用 returnDoc=true 可返回更新后的完整文档。如果文档不存在且 upsert=false,返回 404。

Request

Path Parameters

    collectionName stringrequired

    集合名称

    docId stringrequired

    文档 ID(支持 ObjectId 字符串和普通字符串)

Body

required
    data objectrequired

    更新数据(EJSON 对象),支持更新操作符

    replaceMode boolean

    是否替换整个文档

    upsert boolean

    不存在时是否创建

    returnDoc boolean

    是否返回更新后的文档

    transactionId string

    事务 ID

Responses

更新成功

Schema
    updated integer

    更新的文档数量

    matched integer

    匹配的文档数量

    upsert_id string

    upsert 创建的文档 ID(如有)

    doc object

    更新后的文档(仅 returnDoc=true 时返回)

Loading...