How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

Filter documents by ID in Sanity Desk Structure

8 repliesLast updated: Nov 29, 2025

I’m trying to figure out how to filter out a document by an ID in sanity studio using desk structure
S.listItem()
        .title("Audit template")
        .icon(FaBible)
        .child(
          S.document()
            .schemaType("revisionTemplate")
            .documentId("sourceDocument")
        ),
      S.listItem()
        .title("Audits")
        .child(
          S.document()
            .filter((item) => item.getId() !== "sourceDocument")
            .schemaType("revisionTemplate")
        ),
Here I’m trying to keep the version of revisionTemplate with a set documentId seperated from all the instances of the document
AI Update

Looking at your code, I can see the issue. When you want to create a filtered list of documents in Structure Builder, you should use S.documentList() or S.documentTypeList() instead of S.document(), since S.document() is for rendering a single specific document, not a list.

Here's how to fix your code:

S.listItem()
  .title("Audit template")
  .icon(FaBible)
  .child(
    S.document()
      .schemaType("revisionTemplate")
      .documentId("sourceDocument")
  ),
S.listItem()
  .title("Audits")
  .child(
    S.documentList()
      .title("Audits")
      .filter('_type == "revisionTemplate" && _id != "sourceDocument"')
      .schemaType("revisionTemplate")
  ),

The key changes:

This setup will give you two separate list items in your Structure:

The Structure Builder documentation explains that S.documentList() is specifically designed for creating filtered lists of documents, and it accepts GROQ filter strings to query which documents to display. You can also check out the getting started guide for more examples of filtering and organizing documents.

Show original thread
8 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions