How to select and edit a specific dataset in Sanity Studio Desk?
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:
Using Environment Variables (Recommended)
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 startAlternative: Multiple Studio Instances
Another approach is to maintain separate Studio directories or configurations for each dataset. You could:
- Duplicate your Studio folder
- Update the
datasetvalue in eachsanity.jsonto point to different datasets - 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.localfile should be added to your.gitignoreto 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 thread3 replies
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.