How to create and switch between staging and production datasets in Sanity Studio?

4 replies
Last updated: Jun 12, 2023
Hi everyone,
Would like to create 2 datasets in a project, one - "production" and other- "staging".
How can I create Studios simultaneously for both and switch between them on Studio (on the Web/without using CLI)?

When create a data at staging, how can I utilize them at production?
Imagine that edit blog post at staging and then open it to the public at production.
AI Update

Great question! Setting up multiple datasets with staging and production workflows is a common pattern in Sanity. Let me walk you through how to do this.

Creating and Switching Between Datasets in Studio

You can use Workspaces to manage multiple datasets within a single Studio deployment. This lets you switch between your staging and production datasets right from the Studio UI without touching the CLI.

Here's how to set it up in your sanity.config.ts:

import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
import {schemaTypes} from './schemas'

export default defineConfig([
  {
    name: 'production',
    title: 'Production',
    projectId: 'your-project-id',
    dataset: 'production',
    plugins: [structureTool()],
    schema: {
      types: schemaTypes,
    },
  },
  {
    name: 'staging',
    title: 'Staging',
    projectId: 'your-project-id',
    dataset: 'staging',
    plugins: [structureTool()],
    schema: {
      types: schemaTypes,
    },
  },
])

Once configured, you'll see a dropdown in the top-left corner of your Studio that lets you switch between "Production" and "Staging" workspaces. Each workspace connects to its respective dataset, and you can switch between them instantly in the browser - no CLI needed!

Moving Content from Staging to Production

Now for the trickier part: moving edited content from staging to production. Unfortunately, Sanity doesn't have a built-in "promote to production" button for moving content between datasets. Here are your options:

Option 1: Cross Dataset Duplicator Plugin (Easiest for Individual Documents)

The Cross Dataset Duplicator plugin lets you copy individual documents and their assets between datasets directly from the Studio UI:

npm i @sanity/cross-dataset-duplicator

This is great for your blog post scenario - you can edit a post in staging, then use the plugin to copy it to production when you're ready to publish. However, it's more manual and works best for copying individual documents rather than bulk operations.

Option 2: Export/Import via CLI (Better for Bulk Operations)

You can export specific content from staging and import it to production using the CLI:

# Export from staging
sanity dataset export staging staging-backup.tar.gz

# Import to production (merges with existing content)
sanity dataset import staging-backup.tar.gz production

For selective migration of specific documents (like just blog posts), you can use GROQ queries:

sanity documents query --dataset staging "*[_type == 'post']" | jq -c ".[]" > posts.ndjson
sanity dataset import posts.ndjson production

Option 3: Content Releases (Different Approach)

If your goal is more about "draft vs published" workflow rather than true environment separation, consider using Content Releases instead. This feature (available on Growth plans and above) lets you bundle multiple document changes and publish them atomically within the same dataset. It's designed for the exact use case you described - editing content and then making it public when ready.

Important Considerations

  • Datasets are isolated: Content in one dataset can't directly reference content in another (unless you're on an Enterprise plan with cross-dataset references)
  • Schema is shared: Both workspaces use the same schema definition from your codebase, though you can conditionally show/hide document types per workspace
  • Free plans include 2 datasets: Perfect for your production + staging setup

The workspaces approach gives you the best "switch between datasets in the Studio" experience, while the Cross Dataset Duplicator plugin provides the easiest way to move individual pieces of content between them when you're ready to go live.

Show original thread
4 replies
Many thanks!!!!Perfect.

So, appreciate if you could show how to reuse the post in staging, as well. Do we have a method to upload/edit rawjson on Studio?
you could perhaps have an attribute that "opens" it to the public and a webhook that, once the attribute is "true" (using GROQ filters) you add/update the document into prod?
Will investigate around there.Thanks a lot.

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.

Was this answer helpful?