Skip to content
This page View Markdown Open in ChatGPT Open in Claude

returnDocument

returnDocument decides which version of the row an update by id or a replace by id sends back : the row after the change (the default) or the row before it.

Value The response holds
after (default) The row as it is now, with the fields you changed.
before The row as it was, so you can show or log what changed. The update happens all the same.
PUT /api/schema/admin/mysql8/inventory/customers/update-by-id/1?returnDocument=before
Body
{ "pincode": 382330 }
Response with returnDocument=before
{
    "success": true,
    "statusCode": 200,
    "data": { "customer_id": 1, "first_name": "Bob", "last_name": "Lin", "pincode": 382345 }
}
  • It only changes the response, never what is written.
  • It works with select and deep : both apply to the version returned.
  • From code : g.sys.db.updateById({ ..., returnDocument: 'before' }).