title: Best method to upload data to multiple documents in Firestore
body: <p>I am currently working on an iOS App that uses Cloud Firestore from Firebase.</p>
  <p>I was wondering: what is the best way (cost, efficiency and security-wise) to upload some data to multiple Firestore documents simultaneously (or almost simultaneously)?</p>
  <p>* The data I have to upload consists of the following: there are two users (User A is the user currently using the app, User B is the one whose profile is currently being seen by User A). If User A saves User B's profile, I must upload User B's UID to User A's Firestore Document. Then, I have to increase a counter in User A's Firestore Document. Finally, I must add User A's UID to User B's Firestore Document. - Note that with Firestore Document I mean either a document Field or a document Subcollection.</p>
  <p>The choices are:</p>
  <ul>
  <li><p><strong>Upload everything from the client</strong>: seems the best method, cost-wise: it doesn't require extra Cloud Functions usage. I would create a Batch Operation and upload all the data from there*. The downside is that the client must be able to access multiple unrelated collections and documents.</p>
  </li>
  <li><p><strong>Update one document from the client, then update everything else from Cloud Functions</strong>: this method is the best one efficiency and security-wise; the client only uploads data to the user's document*, without accessing unrelated collections and documents. Also, the client only has to upload a fraction of the data that it had to upload in the previous method, saving bandwidth and cellular data / WiFi usage. The downside is that the usage of Cloud Functions would increase, eventually resulting in more costs.</p>
  </li>
  <li><p><strong>Update one document from the client, update the counter* from the client and then update everything else form Cloud Functions</strong>: this method is somewhat a hybrid between the first two, as I think that updating the counter from the client is more secure (Cloud Functions' <code>.onWrite</code> trigger may happen twice or more, increasing the counter multiple times?).</p>
  </li>
  </ul>
  <p>My first thought was to go with method 2, as it's far more secured and efficient, but I would like to have someone else's advice too, before &quot;wasting&quot; too much time coding something wrong.</p>
  <p>I hope this isn't any kind of duplicate, as I couldn't find anything that answered my question with enough specificity.</p>
  <p>Any advice would be much appreciated. Thank you.</p>