title: .setTimeout() inside for loop to update data (mongoDB)
body: <p>I'm trying to make the &quot;Bee&quot; to sleep for 5 seconds when it's energy becomes 0, then it'll regains back it's all stats. However, it's stats has became 0 after the command is executed, but after 5 seconds it wouldn't regain back the stats. Any idea how to fix it?</p>
  <pre class="lang-js prettyprint-override"><code>// some codes above (unrelated)
  Hive.findOne({ User: message.author.id }, async (err, data) =&gt; {
      // some codes here (unrelated)
      const arr = [];
      const en = Object.keys(data.Hives).map((key) =&gt; {
          return data.Hives[key].Energy
      })
      for (let a = 1; a &lt; en.length + 1; a++) {
          if (!isNaN(data.Hives[`Hive${a}`].Energy)) {
              data.Hives[`Hive${a}`].Energy -= 1
              if (data.Hives[`Hive${a}`].Energy &lt; 1) {
                  arr.push(` Your ${data.Hives[`Hive${a}`].Bee} is out of energy! It's going to sleep.`);
                  data.Hives[`Hive${a}`].Gathers = 0;
                  data.Hives[`Hive${a}`].Converts = 0;
                  // --- where the problem begins ---
                  setTimeout(async() =&gt; {
                      data.Hives[`Hive${a}`].Energy = data.Hives[`Hive${a}`].MaxEnergy;
                      data.Hives[`Hive${a}`].Gathers = 2.5 * (1 + 0.1 * (data.Hives[`Hive${a}`].Level - 1));
                      data.Hives[`Hive${a}`].Converts = (80 * (1 + 0.1 * (2 - 1)) * statsProfile.ConvertRate) / 100;
                  }, 5000);
              // --- where the problem ends ---
              };
          };
      };
      if (arr.length != 0) {
          message.reply({
              embeds: [
                  new Discord.MessageEmbed()
                      .setTitle(&quot;Out of energy...&quot;)
                      .setDescription(arr.join(`\n`))
                      .setColor(&quot;ffbe42&quot;),
              ],
          });
      }
      //some codes here as well (unrelated)
  
      await Hive.findOneAndUpdate(user, data);
  });
  
  </code></pre>
  <p>I've tried putting <code>await data.save()</code> inside and before <code>.setTimeout()</code></p>