title: Firebase Multiple Collection Update
body: <blockquote>
    <p>Is there a way to update two documents, each in a different
    collection, in <strong>one</strong> request?</p>
  </blockquote>
  
  <p>I know you can batch write using <code>FIRWriteBatch</code> - this seems to be limited to the <em>same</em> collection for any document updates. When trying to attach updates for documents in two different collections:</p>
  
  <pre><code>// Just for example
  FIRWriteBatch *batch = FIRWriteBatch.new;
  
  [batch updateData:@{@"posts" : @1} forDocument:[self.firebase.usersCollection documentWithPath:@"some_user_id"]];
  [batch setData:@{@"test" : @"cool"} forDocument:[self.firebase.postsCollection documentWithPath:@"some_post_id"]];
  
  [batch commitWithCompletion:^(NSError * _Nullable error) {
  
      NSLog(@"error: %@", error.localizedDescription);
  
  }];
  </code></pre>
  
  <p>It never executes - the app crashes and I get this:</p>
  
  <pre><code>Terminating app due to uncaught exception 'FIRInvalidArgumentException', reason: 
  'Provided document reference is from a different Firestore instance.'
  </code></pre>
  
  <hr>
  
  <p>Apparently the batch does not like updates in more than one collection.</p>
  
  <ul>
  <li>Does anyone know how you can update two documents, each in a different collection, without one failing and the other succeeding?</li>
  </ul>
  
  <p>I want to avoid, for example, successfully setting <code>posts = 1</code> for a document in <strong>usersCollection</strong>, while <strong>failing</strong> to write a new document in <strong>postsCollection</strong>.</p>
  
  <p>I understand it's pretty unlikely that one will write while the other fails, but in the case that it <strong>does</strong> happen, I obviously don't want inconsistent data.</p>
  
  <hr>
  
  <p><strong>NOTE:</strong></p>
  
  <p>For anyone who cares - I don't know if it ever <em>will</em> fail, but as of now I am running the transaction <strong>without</strong> reading the document before updating data... ‍♂️ Cheers to -1 API call!</p>