See Sanity in action 👀 Join us for a live product demo + Q&A →

Using paths to handle data separation in datasets

39 replies
Last updated: Mar 1, 2023
Is there any way to pay for additional datasets without going for the Enterprise plan? I think we’d need 12 at work to migrate from Contentful.
Feb 28, 2023, 11:32 PM
No, datasets are unfortunately not available a la carte. However, it’s very unlikely that you actually need 12 datasets, since there are methods of separating data within a single dataset. What do you need the datasets for?
Feb 28, 2023, 11:59 PM
6 countries prod and the same for a testing/dev/staging env
Feb 28, 2023, 11:59 PM
Each country has different data handled by different teams
Mar 1, 2023, 12:00 AM
It’s not localization
Mar 1, 2023, 12:00 AM
You won’t need to separate the countries. You can get away with three datasets (testing/dev/staging) and use paths and a custom desk structure to handle the different data from different countries.
Mar 1, 2023, 12:01 AM
I looked a little bit at that before. Would we need to add the “country/market” as a field on every schema type?
Mar 1, 2023, 12:01 AM
Our merch teams can’t be picking that option when creating/editing things, so jt would have to be hidden and auto-selected.
Mar 1, 2023, 12:02 AM
No, you could handle that with the paths you set up and possibly initial values (unlikely if you have the paths set up correctly, though).
Mar 1, 2023, 12:03 AM
Mar 1, 2023, 12:04 AM
Mar 1, 2023, 12:04 AM
ah so prefixing ids with the country
Mar 1, 2023, 12:05 AM
can you query a collection where the ids contain x then as well?
Mar 1, 2023, 12:05 AM
say I want all of SchemaType for Country
Mar 1, 2023, 12:07 AM
We do similar things with the source of tickets in Support here:
when it comes time to query we can use the
function to separate things (
_id in path('**')
). You can then add other filters to limit it to a certain schema type. Putting it all together, this would get me all of the products under the French market:
*[_type == 'product' && _id in path('fr.**')]
Mar 1, 2023, 12:11 AM
Mar 1, 2023, 12:11 AM
And a reference in the sanity UI, can I make that only show, say the fr. tags for a product in fr.?
Mar 1, 2023, 12:12 AM
If would be good if that kind of thing wasn’t completely manual for each field, Querying is easier because you start from the top
Mar 1, 2023, 12:14 AM
Do you mean translation of the Studio’s UI (like headings and field names) or tag data in your dataset? If it’s the former, unfortunately, the Studio cannot have different translations. If it’s the latter you sure can!
Mar 1, 2023, 12:14 AM
There’s no translations. Here’s the senario. Assuming we have a Product schema type and a Tag schema type (like vegan, gluten-free, whatever):
Mar 1, 2023, 12:16 AM
Then we have a team who only cares about the fr. data
Mar 1, 2023, 12:16 AM
Can they view the studio in a way that they by default only see fr. Products, and if they were to add a reference to a Tag on a Product, the dropdown of available Tags also only show fr. tags.
Mar 1, 2023, 12:17 AM
Yeah, totally
Mar 1, 2023, 12:21 AM
You’d handle that with the same
function in the schema’s filter
Mar 1, 2023, 12:22 AM
Awesome, might go with sanity then!
Mar 1, 2023, 12:22 AM
do it
Mar 1, 2023, 12:22 AM
I will tell my colleague about this functionality. It was the main blocker.
Mar 1, 2023, 12:22 AM
Except for migrating ofc
Mar 1, 2023, 12:23 AM
But I’m loving the embedded studio and the schema-driven development on my personal site already.
Mar 1, 2023, 12:23 AM
Thank you for answering my questions!
Mar 1, 2023, 12:24 AM
Of course! When it comes time to migrate, you can make it a bit easier for yourself using this repo.
Mar 1, 2023, 12:24 AM
Awesome! I suspect we’d need to tweak a bit given what we currently have
Mar 1, 2023, 12:26 AM
But should be helpful to start.
Mar 1, 2023, 12:26 AM
Paths are great if only creating via the api but there is no real way ive found to setup initial _id values. We have a couple sites setup with reference fields to a ‘site/language’ field that is hidden for editors and autofilled by initial value templates based on the current desk structure context. Happy to send you some examples Alvar
Mar 1, 2023, 5:15 AM
And this dataset limitation is pretty annoying. You could also have multiple projects with the same schema
Mar 1, 2023, 5:17 AM
Please do send!
user A
Mar 1, 2023, 6:06 AM
user M
How does ID generation work?

The Sanity Studio automatically generates a random UUID for new documents (e.g. 189bc292-e41b-42a0-91b5-bfaa33a34af2), and does not allow you to specify an ID yourself, but you are free to use your own ID scheme for documents that you create using the HTTP API.
Mar 1, 2023, 11:40 AM
Do I have to call an API instead of using the UI to create?
Mar 1, 2023, 11:40 AM
You can use an initial value and a custom publish action to preserve your paths.
Mar 1, 2023, 5:34 PM – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.