title: How to update a list of users in Firestore using Firebase admin sdk?
body: <p>So I'm learning how to use the firebase admin sdk and I've come across a problem that I'm not understanding enough to solve. Basically, I've queried my database and gotten a subset of users that I would like to update with the same value. So I stored the id's of each user that I want to update in an array, now I am trying to loop through that array and update each user. But I'm having a problem implementing this part and it has to do with the fact that .update() returns a promise and I'm not 100% how to handle this in a loop...</p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  admin.initializeApp()
  exports.getAllUsers = functions.https.onRequest((request, response) =&gt; {
    const db = admin.firestore()
    const users = db.collection('users').where('role', '==', 'artist').get()
      .then(function (querySnapshot) {
        //const users = querySnapshot.data()
        const promises = []
        querySnapshot.forEach(function (doc){
          promises.push(doc)
        })
        return Promise.all(promises) //returning promises sends the resolved results to 
      })                             //to the next .then()
      .then(function (person){
        let results = []
        person.forEach(function(personSnap){
          //const data = personSnap.data()
          results.push(personSnap.id)
        })
        return results  // results is the array of ids to update
      })
      //This .then() is where I have trouble understanding how to update
      .then(function (ids){
        for(var i = 0; i&lt;ids.length; i++){
          var artistsRef = db.collection('users').doc(ids[i]);
  
          artistsRef.update({ //Should not be a return statement. This fixed my problem. Otherwise it would update the first user in the array and then leave the for loop.
            'free_credits': '2'
          })
        }
        return 'finished'
      })
      .then(function(reply) {
        return response.send(reply)
      })
      .catch(function (error){
        response.send(error)
      })
  
  })
  </code></pre>
  
  <p>I feel like I should be returning 'artistsRef.update()' since it is a promise but I think that leads to unexpected results. </p>
  
  <p>If I don't return the update() then ESLint throws the error: "Each then() should return a value or throw"</p>