Exploring Sanity? Take control of your content – watch the demo

Using sanity migration to add new documents in Sanity.io

3 replies
Last updated: Jan 9, 2025
Is it possible to use a sanity migration to add new documents? I only see how to access and iterate over existing documents/nodes/objects using the
migrate
property.
Jan 9, 2025, 6:54 PM
Yes, it's possible! You can use the create* functions from
sanity/migrate


https://www.sanity.io/docs/reference/api/sanity/migrate/createIfNotExists
Jan 9, 2025, 7:23 PM
What is your use case? The
migrate
property is primarily built for you to access existing content, but I guess you can run any JS within those things to do what you need to do
Jan 9, 2025, 7:24 PM
Ah, ok... I got hung up that I don't need a
document()
function in there and I can just start writing my javascript inside of the migrate. All good thanks!
Jan 9, 2025, 7:31 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?