How can one update fields in a document's nested object? The documentation indicated dot notation but how do you achieve the update with a variable as the object name?
Structure is like: collection("fruits").doc("as867f56asd")
name: "banana"
abc-variable:
description:"blah"
qty: 1
I want to update document as867f56asd's abc-variable.qty = 2
My JavaScript requires the use of a variable for the object name.
I can't figure out bracket notation for the update. Is .set{merge:true} req'd?
Here is the code I've tried so far (rough paste):
qty = evt.target.value;
//create a string
var obj = firebase.firestore.FieldPath(item).quantity;
//str = item + '.quantity';
//obj[str] = qty;
// var myUpdate = {};
// myUpdate['${item}.quantity'] = qty;
//var obj = [item]["quantity:"] = qty;
console.log("item is " + item);
//var obj = {"'" + item + "'.quantity" : qty};
//obj[item]["quantity"] = qty;
console.log("qty is " + qty);
orderRef.update (
{obj:2}
//{"quantity":qty}
//[item + '.quantity']: qty
//[`favorites.${key}.color`] = true
// ['${item}.quantity'] : qty
//[`hello.${world}`]:
//{[objname]}.value = 'value';
//['favorites.' + key + '.color']: true
//[item]["quantity"] = qty // err:reqd 2 args
//item["quantity"] = qty
//"favorites.color": "Red"
//{"`item`.quantity": qty}
//{"quantity":qty}
)