title: Check number of active orders in firebase
body: <p><a href="https://i.stack.imgur.com/FY0B0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FY0B0.jpg" alt="DB" /></a>
  <a href="https://i.stack.imgur.com/U4ykI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U4ykI.jpg" alt="View" /></a>
  I was trying to retrieve total active orders from my firebase DB. But every time it returns the incorrect output. I am using onClick function to get totalActiveOrder. totalActiveOrder is added when the status of the MEALID is placed or accepted.</p>
  <p>Is it possible if I deploy a cloud function and monitor totalActiveOrder in the backend? I was searching online but I can't find any solution.
  I have attached the screenshot of my DB and here's my approach</p>
  <p>What I am doing is. When the order is placed from the App. that time the status is &quot;placed&quot;.
  When the restaurant accepts the order then the status changes to &quot;accepted&quot;
  When an order is prepared then the status changed to &quot;ready&quot;
  When an order is picked by the customer then it changes to &quot;picked&quot;</p>
  <pre><code>checkActiveOrder = (uid) =&gt; {
          let activeOrder = 0
          firebase.database().ref('orders/' + uid + &quot;/&quot;).once('value').then(snapshot =&gt; {
              snapshot.forEach(dataSnap =&gt; {
                  let status = dataSnap.val().status
                  console.log(status)
                  if (status === &quot;placed&quot; || status === &quot;accepted&quot;) {
                      activeOrder++
                  }
              })
              console.log(activeOrder)
          });
      }
      //trigger when button is clicked
      handleClick = async (uid, mealId, type) =&gt; {
          this.checkActiveOrder(uid)
          let status = getNextStatus(type);
          function getNextStatus(type) {
              switch (type) {
                  case 'placed': return &quot;accepted&quot;;
                  case 'accepted': return &quot;ready&quot;;
                  case 'cancel': return &quot;cancel&quot;
                  case 'ready': return &quot;picked&quot;;
                  case 'decline': return &quot;decline&quot;;
                  default: return null
              }
                 await firebase.database().ref('orders/' + uid + &quot;/&quot; + mealId + '/status').set(status);
      }
  </code></pre>