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)
- application/json
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
- 200
- 404
Update successful
- application/json
- Schema
- Example (from schema)
- without_doc
- with_doc
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)
{
"updated": 0,
"matched": 0,
"upsert_id": "string",
"doc": {}
}
Without document return
{
"updated": 1,
"matched": 1,
"upsert_id": ""
}
With updated document (returnDoc=true)
{
"updated": 1,
"matched": 1,
"upsert_id": "",
"doc": {
"_id": {
"$oid": "507f1f77bcf86cd799439011"
},
"name": "John",
"age": {
"$numberInt": "31"
}
}
}
Document not found
- application/json
- Schema
- Example (from schema)
Schema
code string
Error code
message string
Error message
request_id string
Unique request ID
{
"code": "INVALID_PARAM",
"message": "param.query can't be empty",
"request_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
Loading...