How to reduce attribute count by removing content in Sanity project?

6 replies
Last updated: Jun 14, 2023
Hi there šŸ‘‹ I have reached the attribute limit on a project. I am trying to remove some content we no longer need in the hope it will bring the attribute count down, but isn’t going down. Am I missing the point of attributes here? Any suggestions would be great, thank you šŸ™
AI Update

You're not missing the point of attributes - you've actually identified a key behavior that can be confusing! Let me explain what's happening and how to fix it.

Why deleting content isn't reducing your attribute count

According to the attribute limit documentation, attributes work differently than you might expect:

Your attribute count:

  • Goes up when you first add content on a path
  • Goes down when a path no longer holds any content across all documents
  • Stays the same regardless of whether a path is used once or many times

The key issue: Each unique path is counted once, no matter how often it's used. Removing a path from your attribute count requires deleting every piece of content on that path across all documents in your dataset - not just some documents.

So if you deleted a few documents but other documents still contain those same field paths, your attribute count won't decrease.

How to actually reduce your attribute count

Here's what you need to do:

1. Export your data first (critical!)

Before making any changes, run a full export:

sanity dataset export production production.tar.gz

2. Track your progress

Monitor your attribute count using this URL:

https://<projectId>.api.sanity.io/v1/data/stats/<datasetName>

Look for fields.count.value (current count) and fields.count.limit (your limit).

3. Identify and remove unused paths

You need to remove content from paths that are no longer needed. This might include:

  • Old document types that are no longer in your schema
  • Deprecated fields within existing document types
  • Nested structures you've refactored

The content must be removed from every document that contains those paths, including drafts (documents with drafts. prefix in their ID).

4. Consider restructuring

If you're still hitting limits, you may need to restructure your content model. Common issues that inflate attribute counts:

  • Excessive nesting with block content inside custom objects
  • Translation/localization that duplicates fields for each language (wrapping fields in language objects multiplies your count)
  • Over-customization with too many presentational fields instead of focusing on semantic content

Check out the best practices section in the docs for detailed guidance on avoiding these pitfalls.

Hope this helps! Let me know if you need help identifying which paths are consuming your attributes.

Show original thread
6 replies
Removing content will only be effective if you’re removing all of the content that uses a particular unique path. If one document still uses that path the attribute limit won’t go down.
I assumed this might be the case after pondering over it. Thank you for coming back to me I appreciate the confirmation šŸ™‚
For sure! It’s tricky wrap your head around.
Hey
user M
- I was wondering if I could seek help with this again please? We have removed the content from the respective fields but the attribute limit hasn’t changed (I’m fairly certain it’s increased actually šŸ™ˆ). I haven’t removed the fields from the schema though, do I have to remove the fields after the content, or should the content removal reduce the attribute count? Thank you šŸ™
Removing the content should get rid of the paths, since the backend isn’t aware of your schema definitions. It sounds like there are possibly still some documents that are using those paths. They could not be visible within your Studio if they were in documents that you stopped using. Have you tried using GROQ to find them all?
Hey
user M
thanks for coming back to me, I’ll try running some queries to see if I can identify them

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?