Should I use SKU field in documents or create separate SKU document type?

5 replies
Last updated: Jan 28, 2026
Hi all. I have multiple document types that together form a product catalog. I will need an easy way to query by SKU, and I am not sure what the best way to proceed. Should I add SKU to individual documents and then use some aggregate query for it? Or should I create a new document type that will hold the unique global SKU and reference the product document types?
AI Update

Based on the information about product catalog management in Sanity, I'd recommend adding SKU directly to your individual product documents rather than creating a separate document type. Here's why:

Direct SKU approach (recommended):

  • Store the SKU field directly on each product document type
  • Query by SKU using GROQ filters like *[_type == "product" && sku == "ABC123"][0]
  • This is the standard pattern used in e-commerce implementations with Sanity

Why this works better:

  1. Simpler queries: You can directly query any document type by SKU without needing to traverse references
  2. Better performance: Direct field queries are faster than reference lookups
  3. Easier maintenance: No need to keep separate SKU documents in sync
  4. Flexibility: Each document type can have its own SKU while still being queryable

If you need to query across multiple document types:

You can use a GROQ query that searches multiple types at once:

*[_type in ["productType1", "productType2", "productType3"] && sku == $sku][0]

Or if you want to find all documents with a specific SKU regardless of type:

*[defined(sku) && sku == $sku]

When you might consider a separate SKU document:

The separate document approach only makes sense if:

  • You need complex SKU-specific metadata that doesn't belong on product documents
  • You're managing SKUs that can point to different product types over time
  • You need a central registry for SKU allocation/validation

But for most product catalogs, the direct approach is cleaner and more maintainable. As mentioned in the structured content patterns for e-commerce guide, storing SKUs directly on product documents (often within variant arrays) is the standard pattern in e-commerce implementations.

Show original thread
5 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.

Was this answer helpful?