title: Bluebird Promisfy.each, with for-loops and if-statements?
body: <p>Right now, the parent for-loop (<code>m &lt; repliesIDsArray.length</code>) completes before the first findOne fires, so this all only loops through the last element of the repliesIDsArray..asynchronous..</p>
  
  <p>What's the proper syntax for a promisified version of this codeset? Am new to promisification, and wondering how to start this promisify + loop through arrays + account for if-statements..</p>
  
  <p>Bluebird is required, and <code>Promise.promisifyAll(require("mongoose"));</code> is called.</p>
  
  <pre><code>for(var m=0; m&lt;repliesIDsArray.length; m++){
  
  objectID = repliesIDsArray[m];
  
  Models.Message.findOne({ "_id": req.params.message_id},
      function (err, doc) {
          if (doc) {
           // loop over doc.replies to find the index(index1) of objectID at replies[index]._id
           var index1;
           for(var i=0; i&lt;doc.replies.length; i++){
              if (doc.replies[i]._id == objectID) {
                  index1 = i;
                  break;
              }
           }
           // loop over doc.replies[index1].to and find the index(index2) of res.locals.username at replies[index1].to[index2]
           var index2;
           for(var j=0; j&lt;doc.replies[index1].to.length; j++){
              if (doc.replies[index1].to[j].username === res.locals.username) {
                  index2 = j;
                  break;
              }
           }
  
           doc.replies[index1].to[index2].read.marked = true;
           doc.replies[index1].to[index2].read.datetime = req.body.datetimeRead;
           doc.replies[index1].to[index2].updated= req.body.datetimeRead;
           doc.markModified('replies');
           doc.save();
      }
  }); // .save() read.marked:true for each replyID of this Message for res.locals.username
  
  } // for loop of repliesIDsArray
  </code></pre>