How to select and edit a specific dataset in Sanity Studio Desk?

3 replies
Last updated: Jun 12, 2023
I have a website using a production dataset with all the content already filled. I would like to create a production clone of this website but with some changes on the dataset content, no the structure. I’m currently using sanity v2, I tired creating a new data set on the same project and coping the contents from the original dataset to the new, this worked for cloning the dataset however I’m not sure how to select which dataset I want to edit when working on the Sanity Studio Desk. Any ideas? Thank you! 🙏
AI Update

Great question! For Sanity Studio v2, switching between datasets is done through configuration in your sanity.json file and environment variables. Here's how to set it up:

The cleanest approach for v2 is to use environment variables to specify which dataset your Studio should connect to. In your sanity.json, you can reference the dataset using process.env:

{
  "root": true,
  "project": {
    "name": "Your Project Name"
  },
  "api": {
    "projectId": "your-project-id",
    "dataset": "production"
  },
  "plugins": [
    "@sanity/base",
    "@sanity/desk-tool"
  ]
}

Then create .env files to switch between datasets:

For your original production dataset (.env.production):

SANITY_STUDIO_DATASET=production

For your cloned dataset (.env.staging or .env.local):

SANITY_STUDIO_DATASET=production-clone

Update your sanity.json to use the environment variable:

{
  "api": {
    "projectId": "your-project-id",
    "dataset": "${SANITY_STUDIO_DATASET}"
  }
}

Then run your Studio with the appropriate environment:

# For production dataset
sanity start

# For your cloned dataset
SANITY_STUDIO_DATASET=production-clone sanity start

# Or use a different mode
SANITY_ACTIVE_ENV=staging sanity start

Alternative: Multiple Studio Instances

Another approach is to maintain separate Studio directories or configurations for each dataset. You could:

  1. Duplicate your Studio folder
  2. Update the dataset value in each sanity.json to point to different datasets
  3. Run each Studio instance separately

Important Notes

  • Both datasets will use the same schema (which is perfect for your use case since you only want different content, not structure)
  • Environment variables in Sanity v2 must be prefixed with SANITY_STUDIO_ to be automatically picked up
  • The .env.local file should be added to your .gitignore to avoid committing environment-specific settings

Heads Up About v2

Just a friendly reminder that Sanity Studio v2 is now deprecated. When you have time, consider migrating to v3, which has a much better workspaces feature that makes switching between datasets super easy with a dropdown in the Studio UI!

For v3, you'd use workspaces configuration in sanity.config.js which gives you a native UI switcher between datasets - much more convenient than the v2 approach.

Show original thread
3 replies
In V2, you can use the Experimental Spaces API to switch between datasets. Here’s an example of what you would add to your `sanity.json`:
"__experimental_spaces": [
    {
      "name": "production",
      "title": "Prod",
      "default": true,
      "api": {
        "projectId": "my-project-id",
        "dataset": "production"
      }
    },
    {
      "name": "staging",
      "title": "Staging",
      "api": {
        "projectId": "my-project-id",
        "dataset": "staging"
      }
    }
  ],
This worked nicely, thanks!
Great!

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?