0

The example code is below:

exports.updateUser = functions.firestore
    .document('users/{userId}')
    .onUpdate((change, context) => {
      // Get an object representing the document
      // e.g. {'First Name': 'Marie', 'age': 66}
      const newValue = change.after.data();

      // ...or the previous value before this update
      const previousValue = change.before.data();

      // access a particular field as you would any JS property
      //const name = newValue.name; //How does one accesses 'FIRST NAME'

      // perform desired operations ...
    });

If 'FIRST NAME' is replaced by 'name' it is easy, but my data comes from somewhere else where I have no control on the field names. So the field descriptions have spaces between. How do I read them please?

Damandroid
  • 756
  • 9
  • 31

1 Answers1

0

You need to use brackets notation of property accessor for that:

newValue["First Name"]

In the object[property_name] syntax, the property_name is just a string or Symbol. So, it can be any string, including '1foo', '!bar!', or even ' ' (a space).

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84