Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

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 remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?