πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

Issue with deleting old images in Sanity editor due to locked document

8 replies
Last updated: Aug 2, 2022
Hey everyone! I am updating an old studio for a client of mine and I need to delete some old images (using the media plugin).. However the sanity editor is not letting me delete the image because it is locked to an old document (document was named
editorialPage
which we no longer use). I went into my terminal and deleted the document manually using
sanity documents delete editoralPage
, but it says the document is not found.. Very odd. When I check the image reference it still says
A document of the unknown type editorialPage
... Any help with this? Ideally it would just be great to delete that document altogether
Jul 29, 2022, 9:06 PM
Hello
user S
In order to bulk detele, you will need to use this functionality:
https://www.sanity.io/guides/bulk-deletion-using-sanity-cli Or you could use one of those snippets:
https://www.sanity.io/answers/how-to-delete-all-docs-of-a-specific-doc-type-p1605106695431800 Tell me if you were able to delete
editorialPage
with this approach πŸ™‚
Aug 1, 2022, 6:03 PM
user S
is
editorialPage
the
_id
of the document or the title?
sanity documents delete
expects to receive an
_id
of a document so that may be your issue!
If you don't know the
_id
you can first run
sanity documents query '*[title == 'editorialPage']'
. That should print the
_id
for you to use when you run
sanity documents delete
.
Aug 1, 2022, 8:00 PM
Hey
user M
I just tried this.. Seems like it might be the issue. I get the following response back:
--api-version not specified, using `v1
Not sure what this is for..
Aug 2, 2022, 6:23 PM
Can you try adding in an API version like this:
sanity documents query --api-version v2021-06-07 '*[title == "editorialPage"]'
Aug 2, 2022, 6:37 PM
Hmm I just tried that and a blank
[]
is the return object lol. Let me attach a photo of whats going on.. BTW this is a major issue, but it would be great to have old, unused photos deleted.
Aug 2, 2022, 6:47 PM
Oh, that does have a document _id then! If that document is no longer in use, you can just pass that _id into your
sanity documents delete
command.
Aug 2, 2022, 6:48 PM
Haha it worked! πŸŽ‰ Thanks
user M
your're a wizard!
Aug 2, 2022, 6:50 PM
yer a wizard
Aug 2, 2022, 6:53 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?