How to either create or update an existing object

How can i in N1QL either update an existing object in an Array and if it does not exist create a new Object inside the array ? Currently i have the below query where i find the Object inside my array and the replace the object

UPDATE Contacts c USE KEYS $1
SET columns[i] = $3
FOR i: col IN columns WHEN col.colId = $2 END`,

in the above case $3 holds the new or update object and $2 is the colId for the object which is unique

My basic Insert Query looks like this in which case the $2 holds the new object

UPDATE Contacts c USE KEYS $1
SET columns = ARRAY_APPEND(columns,$2)`,

Ideally i would like to find a way to combine both queries into 1


UPDATE Contacts c USE KEYS $1
SET c.columns = (CASE WHEN $2 IN c.columns[*].colId 
                      THEN ARRAY (CASE WHEN v.colId = $2 
                                       TEHN $3
                                       ELSE v 
                                       END) 
                            FOR v IN c.columns 
                            END
                      ELSE ARRAY_APPEND(c.columns,$3)
                      END)

OR

UPDATE Contacts c USE KEYS $1
SET c.columns  = (SELECT RAW col 
                  FROM c.columns AS col
                  WHERE col.colId != $2

                  UNION ALL

                  SELECT RAW $3)