πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

Introducing the document type

In version 0.118.0 we introduced a new type document. This is the type for any object that you would like to store as documents in the datastore. Previously, any object type defined in your schema could be turned into a document, but now you must define these as documents instead. Only document types will appear in the desk tool sidebar.

NOTE: You should still use type: 'object' for the schema types that is reused on fields in your schema types (e.g. things like localeString and other types that you would never create standalone documents of)

What should I do?

This is not a breaking change, so everything will continue to work as before. That is, until the moment you decide to use the document type. If you add a document type to your schema, you should also have to change the type of all the top-level object types in your schema. E.g. if your schema was:

export createSchema({
  name: 'mySchema',
  types: [
    {
      name: 'book',
type: 'object',
fields: [ {name: 'title', type: 'string'} ] } //... ] })

You should change this to:

export createSchema({
  name: 'mySchema',
  types: [
    {
      name: 'book',
type: 'document',
fields: [ {name: 'title', type: 'string'} ] } //... ] })

And do this for all types in your schema that you would like to be stored as documents. Note: you may still want re-usable object types at top-level in your schema, but these should should stay with type objects. In that case they will not be listed in the sidebar.

Note: The introduction of the document type makes the hiddenTypes config in the config/@sanity/data-aspects.json config file obsolete, and you should remove it entirely.

Was this article helpful?