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
  • 297,357
  • 32
  • 422
  • 441
Ben
  • 650
  • 2
  • 12
  • 23

1 Answers1

0

Got it.

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

admin.firestore().collection('mycollection').doc('mydocument').update({ [name] : value})
Ben
  • 650
  • 2
  • 12
  • 23