Automated method to reassign documents from one author to another in Sanity

3 replies
Last updated: Jul 1, 2020
I have `author`’s that are referenced to multiple
document
types.
If I try to delete an
author
I get warnings about all the `document`s they’re connected to.
Is there an automated method to do a find/replace on those documents, to reassign them to another
author
.
I imagine I could write a script to
sanity exec
this, but wanted to check first if there’s already this functionality somewhere. If not, it could probably be a handy plugin…
Jul 1, 2020, 5:51 AM
Hi Simeon, I think you could rework this snippet to get the documents that reference the original author and then patch them to reference the alternative one: https://github.com/sanity-io/sanity-recipes/blob/master/snippets/renameField.js
Jul 1, 2020, 7:15 AM
Hi Simeon, I think you could rework this snippet to get the documents that reference the original author and then patch them to reference the alternative one: https://github.com/sanity-io/sanity-recipes/blob/master/snippets/renameField.js
Jul 1, 2020, 7:15 AM
Figured this would be it. On it, thanks.
Jul 1, 2020, 8:05 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?