Partial update array with values from another array

I have Algolia items that have array fields called ‘tags’. So lets say I have this array inside my item:

tags: [“green”, “red”, “blue”]

I want to update tags with another array [“orange”, “blue”, “white”]. Since blue is already there I want to prevent it from being added to tags.

I know the API supports updating with strings and numbers only but I tried this:

index.partialUpdateObject({
    tags: {
      _operation: 'AddUnique',
      value: tags,
    },
    objectID: "myID",
}, (err, content) => {
    if (err) throw err;
});

This works by adding a new array inside tags array. This is not the behavior I want but I guess the API does not support partial updating arrays with string values from another array.

What is the recommended approach here: getting the item and handling the array by myself and then overwriting the old one?

Hi @vasil.garov,

AddUnique should be used passing the value to add, not the full array.

index.partialUpdateObject({ 
   tags: { 
      _operation: 'AddUnique', 
      value:  **"purple"** , 
   }, 
   objectID: "myID", 
}, (err, content) => { 
   if (err) throw err; 
});

A better approach may be to use saveObject and overwrite the entire array.