Limiting the amount of documents per schema in Sanity and switching to Structure Builder without losing data.
11 replies
Last updated: Jun 9, 2022
S
Hi 👋 first time with Sanity. It's so good! I was just wondering if it is possible to limit the amount of documents that any one schema can make … like here with only wanting one Home Page for example? Or a maximum of 2 say for another document?
Jun 8, 2022, 8:20 PM
K
Hello. Have you checked this document: https://www.sanity.io/docs/create-a-link-to-a-single-edit-page-in-your-main-document-type-list
Jun 8, 2022, 8:40 PM
S
Hi
user F
thank you! Can this only be done via the Structure Builder? My site is finished but it's a collection of documents with a Page Builder as the home page.Jun 9, 2022, 5:35 AM
K
Yes, this can only be done via the structure builder. 🙂
Jun 9, 2022, 7:39 AM
S
Ah ok. Are there any plans to add this at the document level, or to Page Builder?
If I switched now to Structure Builder, would that delete all of the existing content?
If I switched now to Structure Builder, would that delete all of the existing content?
Jun 9, 2022, 8:04 AM
K
I’m a little confused. You wouldn’t switch to the structure builder. Your studio is already using the structure builder. You’re just not customizing it, if you will. So if you were to start customizing it, you wouldn’t lose anything, but the way singleton documents work would mean you would need to redo your documents, yes. Because the idea is that you create the singleton manually in the structure builder configuration, and you disable the option to create them via the studio.
When in doubt, back up your dataset beforehand anyway.
🙂
When in doubt, back up your dataset beforehand anyway.
🙂
Jun 9, 2022, 8:12 AM
S
Ah, I see thank you!
How do I backup my dataset?
How do I backup my dataset?
Jun 9, 2022, 8:14 AM
K
Jun 9, 2022, 8:16 AM
S
Thank you!
Jun 9, 2022, 8:17 AM
S
I could redo my documents as there are only a few but would this also mean changing how I query the data? At the moment I get my data like this
export async function getStaticProps() { const data = await client.fetch( ` *[_type in ["homePage"]]{ _type == "homePage" => { pageBuilder[]->{...} } } `);
Jun 9, 2022, 8:19 AM
K
You can simplify your query a bit:
Your query would still work I think anyway.
🙂
*[_type in "homePage"] { pageBuilder[]-> }
🙂
Jun 9, 2022, 8:21 AM
S
Ah, sorry, I've actually got as I'm passing some data props to a footer and a modal…
export async function getStaticProps() { const data = await client.fetch( ` *[_type in ["footer", "termsAndConditions", "homePage"]]{ _type == "footer" => { ... }, _type == "termsAndConditions" => { ... }, _type == "homePage" => { pageBuilder[]->{...} } } `);
Jun 9, 2022, 8:25 AM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.