Sanity logosanity.ioAll Systems Operational© Sanity 2026
Change Site Theme
Sanity logo

Documentation

    • Overview
    • Platform introduction
    • Next.js quickstart
    • Nuxt.js quickstart
    • Astro quickstart
    • React Router quickstart
    • Studio quickstart
    • Build with AI
    • Content Lake
    • Functions
    • APIs and SDKs
    • Agent Actions
    • Visual Editing
    • Blueprints
    • Platform management
    • Dashboard
    • Studio
    • Canvas
    • Media Library
    • App SDK
    • Content Agent
    • HTTP API
    • CLI
    • Libraries
    • Specifications
    • Changelog
    • User guides
    • Developer guides
    • Courses and certifications
    • Join the community
    • Templates
Content Lake (Datastore)
Overview

  • Understanding Content Lake

    Technical limits
    API Versioning
    API CDN

  • Datasets and documents

    Datasets
    Documents
    Drafts
    IDs and Paths
    Perspectives
    Attribute limit
    Hot swap
    Cloud clone
    Backups

  • Querying with GROQ

    Introduction
    How queries work
    Custom functions
    Query cheat sheet
    Vision plugin
    Syntax reference
    GROQ @ Sanity Learn

  • Querying with GraphQL

    Introduction
    GROQ and GraphQL

  • Mutations

    Introduction to document mutations
    Mutate documents with actions
    Transactions
    Patches
    Document mutation patterns

  • Assets

    Introduction
    Upload, query, and delete assets
    Metadata
    Transformations
    IIIF

  • Content Operations

    Importing Data
    Restore a deleted dataset from a backup
    Migrating your schema and content
    Content migration cheat sheet
    Schema migration principles
    Schema change course @ Sanity Learn

  • Real-time and dynamic content

    Perspectives for preview and presentation
    Live Content API
    Listening API

  • Webhooks

    Introduction
    Best practices
    HTTP API reference
    Toolkit (JS)

  • Embeddings (Experimental)

    Introduction
    Create and query an embeddings index
    Embeddings Index CLI reference
    HTTP API reference

  • Security

    Access Your Data (CORS)
    Browser security & CORS
    Keeping your data safe
    Activity Feed

  • Reference

    GROQ Specification
    Common Sanity document types
    HTTP API
    Roles and permissions
    URL Format
    Authentication
    Using JSONMatch
    IP addresses used by Sanity

On this page

Previous

GROQ and GraphQL

Next

Mutate documents with actions

Was this page helpful?

On this page

  • Core concepts
  • Transactions
  • Patches
  • Actions API
  • Mutations API
Content Lake (Datastore)Last updated December 31, 2025

Introduction to document mutations

Sanity's Content Lake offers a variety of methods for creating, editing, and deleting documents.

Document mutations are how you change content in Sanity's Content Lake programmatically. They provide a structured approach to modifying your documents while maintaining data integrity and enabling collaborative editing.

Some of the things you can do with document mutations include:

  • Create new documents.
  • Delete documents when they're no longer needed.
  • Apply targeted patches to specific fields, or replace entire documents.
  • Make transactional changes across multiple documents.
Want to jump right in?

Mutate documents with actions

The Actions API let you use the same system Sanity Studio uses to mutate documents in Content Lake.

Document mutation patterns

Common patterns and snippets for mutating documents and data in the Sanity Content Lake.

Core concepts

Transactions

When you submit mutations or dispatch actions to Content Lake, they are processed as part of a transaction—a single unit of work that either succeeds completely or fails entirely. Transactions make up a document’s history and trigger listeners.

Learn more about transactions

Transactions

How transactions for Content Lake work

Patches

The Mutations API, and some actions in the Actions API, use patches to make small, targeted changes to documents. Patches allow you to modify specific parts of a document without having to replace the entire document, which is especially useful for collaborative workflows where multiple changes need to be reconciled.

Common patch operations include:

  • set: Update specific fields with new values.
  • setIfMissing: Set values only if the fields don't already exist.
  • unset: Remove fields from a document.
  • insert: Add, remove, or replace elements in arrays.
  • inc/dec: Increment or decrement numeric values.
  • diffMatchPatch: Apply text changes using Google's diff-match-patch algorithm.
Learn more about patches

Patches

The valid patch types when using the direct HTTP mutations api.

Actions API

The Actions API is the preferred method for mutating documents in Sanity—it’s also the underlying API that powers Sanity Studio’s mutations. It's designed to support an authoring model where drafts and versions of a document are iterated on and eventually published.

The Actions API is transactional, meaning that multiple actions will be executed in a single transaction—either all changes are applied, or none of them.

Use the Actions API

Mutate documents with actions

The Actions API let you use the same system Sanity Studio uses to mutate documents in Content Lake.

Actions API reference

Reference documentation for the Actions HTTP endpoint.

Document mutation patterns

Common patterns and snippets for mutating documents and data in the Sanity Content Lake.

Mutations API

The Mutations API is the traditional way of creating and modifying documents in Sanity. It provides low-level operations that give you precise control over your content.

Available mutation types include:

  • create: Create a new document
  • createOrReplace: Create a document or replace it if it exists
  • createIfNotExists: Create a document only if it doesn't already exist
  • delete: Remove a document
  • patch: Apply targeted changes to specific parts of a document

Like the Actions API, the Mutations API is transactional, ensuring data consistency across multiple operations.

Use the Mutations API

Mutation API reference

Reference documentation for the Mutatation HTTP reference.

  • Article
  • Changelog
    New