title: Looping order.find, gather and to send a larger amount of data to front. Poor approach?
body: <p>I'm using express, react and MongoDB. I'm totally new to express and REST API. </p>
  
  <p>I'm trying to implement an analytics portion for my front end on sales, orders etc. The idea is to allow a range of dates to be searched, where each object has a date stamp in which I then compare and gather.</p>
  
  <p>My approach is not working, <code>allOrder</code> doesn't seem to gather all the object as I anticipated. </p>
  
  <pre><code>var allOrder = []; // gather all orders and push them
  
  do {
    Order.find({ date: sDate })
      .then(function(order) {
        allOrder.push(order); //pushing order
      })
      .catch(next);
  
    // create new search date (normally in another function)
    startDate.setDate(startDate.getDate() + 1); // increment a day
    startYear = startDate.getFullYear();
    startMonth = startDate.getMonth() + 1;
    startDay = startDate.getDate();
    if (startMonth &lt; 10) startMonth = "0" + startMonth; // fix format
  
    sDate = `${startYear}-${startMonth}-${startDay}`; // create new search date
    dayStart++;
  } while (dayStart &lt; days); // check the day range
  
  res.send(allOrder); //once all days are done, send.
  </code></pre>
  
  <p>This works in the sense that it increases the day until I reach a certain date. 
  For example, I find for 2018-12-25, then increase a day, and find the next day 2018-12-26. It all works except for when it comes to ending the data back to the front. On each find I <em>do</em> get the all the data, I just can't seem to store it THEN send it all together to the front.</p>
  
  <p>my object model </p>
  
  <pre><code>const orderScheme = new Schema({
    name: { type: String },
    date: { type: String },
    customerName: { type: String },
    customerPhone: { type: String },
    orders: { type: Array }
  });
  </code></pre>