Managing multiple datasets within a project
A dataset is a collection of JSON documents that can be of different types and have references to each other. You can think of a dataset as a “database” where all of your content is stored, whereas the document‘s types would constitute “tables”. Using GROQ or GraphQL you can always query and join data across documents within a dataset, but not across them. Typical applications of datasets are:
- operate with different environments for testing, staging, and production
- localization and segmentation across all content types
- different purpose content, but with same user access and billing
You can also specify which dataset to use with the client libraries (configured when initializing a client) and Sanity Studio (configured in sanity.config.ts or using environment variables).
Enterprise users with the custom access control feature can set custom access control rules for each dataset. Users on regular plans can define public or private visibility mode for their datasets.
Datasets can be created and managed using the
sanity command-line tool, e.g. by running
sanity dataset create <name> or
sanity dataset list. To see all dataset-related subcommands, run
Datasets can also be created and deleted in the project's management console, under the "Datasets" tab.
A dataset name must be between 1 and 64 characters long. It may only contain lowercase characters (
a-z), numbers (
0-9), hyphens (
-), and underscores (
_), and must begin and end with a lowercase letter or number.
You can export and import content to datasets, as well as performing mutations and patches to documents in them.
Customers on the Business plan or above can take advantage of additional functionality for managing datasets in Sanity's architecture. Cloning is available to all projects on Business or Enterprise plans, while hot swapping datasets is only available on the Enterprise plan.
You can initiate dataset copying directly in the cloud and create aliases to hot swap between datasets without changing the underlying code for your project.