title: How to find all instances of a document in multiple subcollections in firestore database?
body: <p>I have a firestore database that stores some documents by their ID in multiple locations. I want to write a function that can access all instances of this document by ID and update/delete them without knowing exactly where they are. </p>
  
  <p>For instance, in a shopping example with multiple users each having a subcollection with a cart, wishlist, and owned. The document ID may or may not exist in each one of the user doc's subcollections. I'm trying to write a function that iterates through these lists and performs the action upon matching the docID, yet have been unsuccessful in finding an example of this. </p>
  
  <p>I understand how to add all references to a batch but not how to find them without a crazy amount of read/write operations over the entire user collection. Is this possible?</p>
  
  <p>My initial thought is to:</p>
  
  <pre><code>    let batch = admin.firestore().batch();
      let allUsers = db.collection('users').get()
        .then(snapshot =&gt; {
          snapshot.forEach(doc =&gt; {
            batch.delete(db.collection('users').doc(doc.id).collection('cart').doc(ID_TO_MATCH));
            batch.delete(db.collection('users').doc(doc.id).collection('wishlist').doc(ID_TO_MATCH));
            batch.delete(db.collection('users').doc(doc.id).collection('owned').doc(ID_TO_MATCH));
          });
        })
        .catch(err =&gt; {
          console.log('Error getting documents', err);
        });
        return batch.commit().then(function () {
            // should delete all the direct referenes
        });
  </code></pre>
  
  <p>This would work, as firestore returns a success for deletion of documents that don't exits. The obvious downside is A LOT of document reads as the number of users grow. Is there anyway to use <code>.where()</code> queries to make this more efficient? </p>