I want to add a new field to document add call it for example 5
.
I have variable which store the field name I want to use.
So when I'm adding a new field I want to call it 5
Code:
let length = "5";
await firestore()
.collection(groupID)
.doc('jobs-list')
.update({
length: licenseNumber,
});
The problem here is that the field name is setting to length
and I want it to be 5
.
CodePudding user response:
Use JavaScript's []
notation for this:
let length = "5";
await firestore()
.collection(groupID)
.doc('jobs-list')
.update({
[length]: licenseNumber,
});