Skip to content

Can a single Sanity dataset contain both public and private documents?

10repliesLast updated: Nov 13, 2026

Is that possible to create a dataset that contains public & private documents, and the client can only access the public data while in the CMS can access both public and private data? Or I can only create different datasets individually?
AI Update

Yes, one dataset can hold both. The approach that works on every plan is to give private documents an _id that contains a dot, such as contacts.abc123. In a public dataset, unauthenticated requests can only read documents whose ID has no dot. Your website, querying without a token, sees only the public documents. Studio users are logged in, so they see everything. Drafts (drafts.<id>) are kept private the same way. On Enterprise you can also use custom roles with GROQ-filtered content resources.

Option 1: Dotted document IDs (any plan)

From IDs and paths: any ID containing . is private, and reading it requires a logged-in user or a token with at least read access. Published IDs at the root (no dot) are public.

Studio generates random UUIDs for new documents and doesn't let you choose the ID, but the API and clients can set a custom _id. Create private documents from code, for example in a server-side function:

import {createClient} from '@sanity/client'

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'production',
  apiVersion: '2025-01-01', // use a current date
  token: process.env.SANITY_WRITE_TOKEN, // server-side only
  useCdn: false,
})

await client.create({
  _id: `contacts.${crypto.randomUUID()}`,
  _type: 'contact',
  email: 'someone@example.com',
})

Your frontend queries without a token and never gets contacts.* documents. In GROQ, authenticated code can select them with *[_id in path("contacts.*")].

Caveats from the docs:

Option 2: Private dataset plus a custom role (Enterprise)

Custom roles and content resources are Enterprise-only. A content resource is a set of documents defined by a GROQ filter, for example _type == "article" && isPublic == true. You create resources under Access > Resources and roles under Access > Roles in sanity.io/manage, or with the Access API. Then assign the role to a robot token for your frontend.

Things to get right:

Option 3: Separate datasets

You can also use a public dataset and a private one, with Studio workspaces to switch between them. Each workspace can have its own schema, so the two datasets don't need to share one. The downside is that moving a document between public and private means copying it to the other dataset.

Plan notes (from the pricing page)

Show original thread
10 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