Replacing all Elements in an Array

I have a doc which has an Array of values which in this case are Int . I am using a script to run a query to get all values from a sql table and insert the elements into the couch base doc. Here is here i have the issue if i go and use the

.arrayAppendAll(path,doc,{createParents: true})

it works if the array is empty or does not exist, if it has the same data already in it it will append the data to the existing array. Since i want to update my data which means replace my data there is no simple call to do so or at least not one which is documented.
so to work around it i use

bucket
      .mutateIn(docID)
      .remove(path)
      .arrayAppendAll(path,doc,{createParents: true})
      .execute((err, result) => {}

this works fine as long as the path exists and can be removed. If it cant be removed at throws an error 1 and ends always on the first doc which i am trying to remove the path which does not exist. Looking at the Docs there seems to be no option or at least its not documented to tell the remove to ignore if it cant remove.

So for now i have to go and check if exists and if it does call a separate function to remove and appendall vs if it does not exist i call a appendall only. It works but its an extra doc request and i was wondering f there is a better way to do this.
Here is a sample of what i am trying to upsert into the doc

“tract_id”: [15259,15260,15261,15262]

Or would it be better just to get the doc and then do the manipulation on my backend and upsert the Doc ? I am trying to do as much on couchbase as possible

Hey @makeawish,

If your looking to simply replace the data, rather than use arrayAppendAll, you can simply upsert the array itself. This will replace the entire array with a new set of entries, whether or not the path exists. This sounds like what you are looking to do, but if I have miss-understood, please let me know!

Cheers, Brett