When using the Sanity client API, do we need to manually set _updatedAt?
No, you do not need to manually set the _updatedAt value when using the Sanity client API. This field is automatically set by the system.
How System Fields Work
According to the Sanity document type documentation, every document in Sanity automatically includes several system fields:
_id- A unique identifier for the document_rev- Revision tracking for version control_createdAt- Timestamp of when the document was created_updatedAt- Timestamp of the last modification
These fields are managed automatically by Sanity's Content Lake. When you create or update a document through mutations (like create, patch, createOrReplace, etc.), Sanity automatically:
- Sets
_createdAtwhen the document is first created - Updates
_updatedAtevery time the document is modified
Important Caveat
While these timestamps are automatically set by the system, there's an important note from the documentation:
"_createdAt and _updatedAt are automatically set by the system to the current time when the document is created or updated, respectively. It is possible to provide a custom value when the document is initially created via a
create,createIfNotExists, orcreateOrReplacemutation. Since the timestamps can be set by a client, they should never be assumed to be accurate."
This means:
- You can manually set these values during initial document creation if needed
- However, for normal operations, you should let Sanity handle them automatically
- Because clients can set these values, they shouldn't be relied upon as a source of absolute truth for security or audit purposes
Best Practice
Simply perform your mutations without worrying about _updatedAt or _createdAt - Sanity will handle these system fields automatically for you. The system automatically updates _updatedAt every time you modify a document through any mutation operation.
Show original thread1 reply
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.