Manually setting `_createdAt` field after creation time in Sanity.io.

3 replies
Last updated: Oct 17, 2023
Is there some way to manually set
doc._createdAt
after creation time? I ran a migration to import a bunch of Markdown docs last week, but sadly forgot to apply the original dates to this field.
Oct 17, 2023, 7:44 PM
I already have a custom
publishedAt
field that I can use for the patch
Oct 17, 2023, 7:45 PM
As far as I can tell though, _createdAt is read-only
Oct 17, 2023, 7:45 PM
Update: After some more searching it does seem like the
_
prefaced fields are readonly.
For future searchers who made the same mistake, here's what I'm doing to move forward:
• Made my custom
publishedAt
field
hidden
in my schema definition, so it will be undefined on all posts created in the future.• On my client, replaced
doc.publishedAt
with
doc.publishedAt ?? doc._createdAt
to account for old posts and future ones.
Oct 17, 2023, 8:03 PM

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.

Was this answer helpful?