How to check efficiently if collection is empty?
<p>… and I stress the word efficiently:</p>

<ol>
<li>Fetching whole collection and calling <code>numChildren()</code> is 
definitely out.</li>
<li>Fetching any item and using <code>exists()</code> is also out, since I don't know keys - they are autogenerated by Firebase when <code>push()</code>ing.</li>
</ol>

<p>This is a subproblem of a well-known 'How to do determine length of a collection efficiently'. </p>

<p>So perhaps there will be yet another, cleaner solution.</p>

<p>My take is:</p>

<pre><code>collectionRef.orderByKey().limitToFirst(1)
  .once('child_added').then(snap =&gt; {
    alert('Not empty');
  });
</code></pre>

<p>The problem is detecting when it's empty.  </p>

<p>The promise returned by <code>once()</code> is suspended in pending state instead of failing instantly if there are no children.  </p>

<p>This approach could be saved by calling <code>off()</code> after some timeout, but 2 issues arise:</p>

<ol>
<li>How to determine the right amount of timeout ?</li>
<li>This workaround with timeout is incredibly lame</li>
</ol>