title: Firebase Cloud Function batch write update document overwrote the entire document?
body: <p>The following Cloud Function has a batch write operation that, in part, updates a single field in a document. This overwrote the entire document and now the document has a single field <code>joinedCount: -1</code>. Is this not the way to update individual fields in documents without overwriting them?</p>
  <pre><code>exports.deleteUserTEST = functions.https.onCall(async (data, _context) =&gt; {
      const uId = data.userId;
      const db = admin.firestore();
  
      try {
          const batch = db.batch();
          const settingsDoc = await db.collection(&quot;userSettings&quot;).doc(uId).get();
          const joinedIds = settingsDoc.get(&quot;private.joinedIds&quot;);
  
          Object.keys(joinedIds).forEach(function(jId, _index) {
              batch.update(
                  db.collection(&quot;profiles&quot;).doc(jId),
                  {
                      private: {
                          joinedCount: admin.firestore.FieldValue.increment(-1), // &lt;-- the culprit
                      },
                  },
              );
          });
          await batch.commit();
      } catch (error) {
          throw new functions.https.HttpsError(&quot;unknown&quot;, &quot;Failed the delete the user's content.&quot;, error);
      }
      return Promise.resolve(uId);
  });
  </code></pre>