Created
June 28, 2022 14:23
-
-
Save coreyward/1e49700b961434c1c7c5f55275061c95 to your computer and use it in GitHub Desktop.
Replace all references - Sanity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import and configure the client | |
const oldRef = "abc123" | |
const newRef = "def456" | |
client | |
.fetch( | |
`*[references($oldRef)][0...250] { | |
_id, | |
_rev, | |
}`, | |
{ oldRef } | |
) | |
.then((docs) => { | |
const tx = docs.reduce( | |
(tx, doc) => | |
tx.patch(doc._id, { | |
ifRevisionID: doc._rev, | |
set: { | |
[`..[_ref == "${oldRef}"]._ref`]: newRef, | |
}, | |
}), | |
client.transaction() | |
); | |
tx.commit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment