0

Trying to use a variable as property when updating a document via Cloud functions. Maybe I miss the syntax here or is it simply not possible.

var value = 'myValue'
var name = 'myVariable'

admin.firestore().collection('mycollection').doc('mydocument').update({ name : value});

The document is updated but it shows then name = myValue and would like to see in the document myVariable = myValue. What would be the syntax to achieve that to be flexible?

Doug Stevenson
  • 268,359
  • 30
  • 341
  • 380
Ben
  • 590
  • 1
  • 9
  • 23

1 Answers1

0

Got it.

var value = 'myValue'
var name = 'myVariable'

admin.firestore().collection('mycollection').doc('mydocument').update({ [name] : value})
Ben
  • 590
  • 1
  • 9
  • 23