Firebase OrderByKey with startAt and endAt giving wrong results
<p>I have 3 objects with the keys as it looks like this:</p>

<p><a href="https://i.stack.imgur.com/6koII.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6koII.png" alt="enter image description here"></a></p>

<p>They are in format of YYYYMMDD. I am trying to get data of a month. But I am not getting the desired output.</p>

<p>When I query it like this:</p>

<pre><code>var ref = db.child("-KPXECP6a1pXaM4gEYe0");

ref.orderByKey().startAt("20160901").once("value", function (snapshot) {
    console.log("objects: " + snapshot.numChildren());
    snapshot.forEach(function(childSnapshot) {
        console.log(childSnapshot.key);
    });
});
</code></pre>

<p>I get the following output:</p>

<pre><code>objects: 3
20160822-KPl446bbdlaiQx6BOPL
20160901-KPl48ID2FuT3tAVf4DW
20160902-KPl4Fr4O28VpsIkB70Z
</code></pre>

<hr>

<p>When I query this along with endAt:</p>

<pre><code>ref.orderByKey().startAt("20160901").endAt("20160932").once("value", function (snapshot) {
    console.log("objects: " + snapshot.numChildren());
    snapshot.forEach(function(childSnapshot) {
        console.log(childSnapshot.key);
    });
});
</code></pre>

<p>I get this: </p>

<pre><code>objects: 0
</code></pre>

<hr>

<p>If I use ~ sign at the end,</p>

<pre><code>ref.orderByKey().startAt("20160901").endAt("20160932~").once("value", function (snapshot) {
    console.log("objects: " + snapshot.numChildren());
    snapshot.forEach(function(childSnapshot) {
        console.log(childSnapshot.key);
    });
});
</code></pre>

<p>I get the output:</p>

<pre><code>objects: 3
20160822-KPl446bbdlaiQx6BOPL
20160901-KPl48ID2FuT3tAVf4DW
20160902-KPl4Fr4O28VpsIkB70Z
</code></pre>

<p>Is there anything I am missing here? </p>