Difference between object type and document type in Sanity

3 replies
Last updated: Mar 13, 2024
What's the difference between
object
type and
document
type
AI Update

The main difference between object and document types in Sanity comes down to whether they can exist as standalone content in your Content Lake:

Document types are top-level content entries that:

  • Can exist independently in your Content Lake
  • Automatically receive system fields: _id, _rev, _createdAt, and _updatedAt
  • Appear in the Content sidebar of Sanity Studio for editing
  • Are queryable as individual entities
  • Examples: blog posts, pages, products, authors

Object types are reusable data structures that:

  • Cannot exist as standalone documents in the Content Lake
  • Are used as building blocks within documents or other objects
  • Do NOT receive the system fields that documents get
  • Do NOT appear in the Content sidebar
  • Must be nested inside a document or another object
  • Examples: address blocks, navigation items, SEO metadata, custom structured data

Think of it this way: documents are the "main content" you create and manage, while objects are the "components" or "building blocks" you use to structure that content.

Here's a practical example from the Object Types documentation:

// Document type - appears in Studio sidebar
{
  name: 'blogPost',
  type: 'document',
  fields: [
    {name: 'title', type: 'string'},
    {name: 'author', type: 'authorInfo'} // uses object below
  ]
}

// Object type - reusable component
{
  name: 'authorInfo',
  type: 'object',
  fields: [
    {name: 'name', type: 'string'},
    {name: 'bio', type: 'text'}
  ]
}

One important note: If you're using GraphQL, you should avoid anonymous inline objects and instead define named object types at the top level of your schema, as GraphQL requires all nested structures to be explicitly defined types.

Show original thread
3 replies
https://www.sanity.io/docs/object-type
By default, object types cannot be represented as standalone documents in the data store. To define an object type to represent it as a document with an ID, revision, as well as created and updated timestamps, you should define with the
document
type. Apart from these additional fields, there’s no semantic difference between a document and an object.
Objects does not appear in the Content area of the sidebar, but document type does.
Hi! Trying to understand this too. What is the use of Objects in schemas if they cant be represented in the data store?

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?