Database

[{"key_array":[1],"another_array":["a"]},{"key_array":[2,3],"another_array":["b"]},{"key_array":[4],"another_array":["c","d"]}]

Query

db.collection.update({"key_array":5},{"$addToSet":{"another_array":"f",},"$set":{"key_array":[5]}},{"upsert":true})

Result