0

I have a Firestore function where

admin
  .firestore()
  .collection('users')
  .doc(context.params.userId)
  .set({field1: false});

The problem is, this replaces the given user object with {field1: false}. I want to be able to add {field1: false} to the object while preserving all other existing fields, and also to be able to remove the field1 field from the object if it already exists.

How should I approach this?

gkeenley
  • 6,088
  • 8
  • 54
  • 129
  • Do this answer your questions ? [how-to-add-new-property-to-an-object-in-cloud-firestore](https://stackoverflow.com/questions/59800228/how-to-add-new-property-to-an-object-in-cloud-firestore) – Syed M Sohaib Feb 23 '22 at 14:47
  • 2
    Use .update() instead of .set() I guess –  Feb 23 '22 at 14:48

0 Answers0