Q:

firestore set with merge true override object

Suppose I have a document with the folowing data (no subcollections)
"kdsjkasdlkfsalk" : {
    favouriteColor: "brown",
    age: 20,
    content: {
      rand1: "randAns1",
      rand2: "randAns2"
    }
 }

Now I want to change favouriteColor and overwrite content without changing age.  Therefore I use:
ref.set({
      favouriteColor: "blue",
      content: {
        newRand: "newRandAns",
        newRand2: "newRandAns2"
      },
    }, {merge:true})

The wanted result:
"kdsjkasdlkfsalk" : {
    favouriteColor: "blue",
    age: 20,
    content: {
      newRand: "newRandAns",
      newRand2: "newRandAns2"
    }
}

The actual result:
"kdsjkasdlkfsalk" : {
    favouriteColor: "blue",
    age: 20,
    content: {
      newRand: "newRandAns",
      newRand2: "newRandAns2",
      rand1: "randAns1",
      rand2: "randAns2"
    }
}

As you can see {merge:true} prevents the overwriting of content and instead just adds new fields.  
I can think of 2 solutions, but they either involve first retrieving all of the data, or first setting content to a boolean and then setting it to the wanted object.  Is there a better way to get the wanted result? 

A:

Instead of using set
You can use update on
"kdsjkasdlkfsalk" : {
favouriteColor: "brown",
age: 20,
content: {
  rand1: "randAns1",
  rand2: "randAns2"
  }
}

You want to do this because you're providing new properties to content.  rand1 vs newRand
Merge will merge the new properties into the existing object. 
Update Example (dot notation)
firebase.firestore().collection("someCol").doc("kdsjkasdlkfsalk").update({
    "color": "someNewColor",
    "content.rand1": "someNewRandValue",
    "content.rand2": "someNewRandValue"
});

or
const content = {
    rand1: "someNewRandValue",
    rand2: "someNewRandValue"
}

firebase.firestore().collection("someCol").doc("kdsjkasdlkfsalk").update({
    "color": "someNewColor",
    content
});

