Join us live Sept. 27 – How Sanity and Vercel powered Morning Brew's transformation –>

Example of updating a deeply nested document with @sanity/client ?

2 replies
Last updated: Sep 12, 2020

hi would anyone have a example of updating a deeply nested document with

@sanity/client
? the kind of stuff you find there https://www.sanity.io/docs/js-client but for objects nested 2 or 3 levels down?

Sep 11, 2020, 11:19 PM

I guess we should improve our docs here, but you can do

client.patch(_id).set({'path.to.nested.key': 'new-value'}).commit()
You can also do it in a transaction like this:
https://twitter.com/kmelve/status/1254470107369222147/photo/1

Sep 12, 2020, 7:50 AM

awesome thanks

Sep 12, 2020, 7:54 AM

Sanity.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.