Prerequisites
- TerminusDB running locally (install guide)
- A connected client instance with existing documents
What you'll achieve By the end of this guide, you will have updated existing documents in your TerminusDB database using the JavaScript client, the Python client, or the HTTP API.
To update a document, first retrieve it, make your changes, then submit the update. The document must include its @id and @type so TerminusDB knows which record to replace.
Update a document
Example: TypeScript
const doc = {
"@id" : "Player/George",
"@type" : "Player",
name : "George",
position: "Center Back",
}
doc.position = "Full Back"
const updateDoc = async () => {
const result = await client.updateDocument(doc)
console.log("Updated document:", result)
}Example: Python
doc = {
"@id" : "Player/George",
"@type" : "Player",
"name" : "George",
"position" : "Center Back",
}
doc["position"] = "Full Back"
client.update_document(doc)curl -u admin:root -X PUT \
"http://localhost:6363/api/document/admin/mydb/local/branch/main?author=admin&message=Update+document" \
-H "Content-Type: application/json" \
-d '{"@id":"Player/George","@type":"Player","name":"George","position":"Full Back"}'The update operation replaces the entire document. Include all fields — any field omitted from the update payload will be removed from the stored document.
Next steps
You've updated documents in TerminusDB. From here you can:
- JSON Diff and Patch — see exactly what changed between document versions
- Branch your database — make changes on an isolated branch before merging
- Delete documents — remove documents you no longer need