Dev-Siri
Dev-Siri

Reputation: 731

Error when inserting a value to an array in Sanity.io

So I'm using sanity .patch() to insert data inside an array. But I'm continously getting this error:

Error: insert(at, selector, items) takes an "at"-argument which is one of: "before", "after", "replace"

Here is my code for reference:

post.js

// ...
{
        name: "peopleLiked",
        title: "People Liked",
        type: "array",
        of: [{ type: "string" }]
}

Where I'm using it:

client.patch(id)
            .insert({
                "before": `peopleLiked.array[0]`,
                
                "items": [auth.currentUser.displayName]
            })

Can anyone help.

Upvotes: 0

Views: 443

Answers (1)

Ricardo Sanchez
Ricardo Sanchez

Reputation: 5167

The insert syntax is wrong, looking at the docs it should be along the lines of:

client.patch(id).insert('before', 'peopleLiked', [{"items": [auth.currentUser.displayName]}])

I'm not familiar with Sanity but looks like you may also need to .commit() after the patch

Hope that helps

Upvotes: 1

Related Questions