title: Firebase queryOrdered, queryEqual not working for sorting and finding on nodes deeper than grandchildren
body: <p>I have looked at a couple of StackOverflow posts on how to get a data value by equating a child value that is few nodes deep.</p>
  <p>In <a href="https://stackoverflow.com/questions/45054550/firebase-database-how-to-perform-a-prefix-wildcard-query/45059681#comment116733215_45059681">Firebase Database - How to perform a prefix wildcard query
  </a> the structure of database is:</p>
  <img src="https://i.stack.imgur.com/Tava2.png" width="300" />
  <p>and the query <code>ref.child(&quot;user_id&quot;).orderByChild(&quot;name&quot;).equalTo(&quot;objective-c&quot;)</code> works in pulling out child with particular uid.</p>
  <p>In <a href="https://stackoverflow.com/questions/40471284/firebase-search-by-child-value">Firebase search by child value</a>, the database structure is:</p>
  <img src="https://i.stack.imgur.com/wuaqA.png" width="500" />
  <p>and the query <code>ref.child('users').orderByChild('name').equalTo('John Doe')</code> is able to pull out the appropriate child.</p>
  <p>In both these cases, the sorting and equating is on the grandchild. In my case, however, the database structure is a bit different. I want to index by a child property that is a few layers deep. The structure is:</p>
  <img src="https://i.stack.imgur.com/iu2KB.png" width="400"/>
  <p>So I tried running the following query: <code>authenticatedUsersReference.queryOrdered(byChild: fcmTokenKey).queryEqual(toValue: fcmToken).observeSingleEvent(of: .value)</code>, and my snapshot returned <code>nil</code>. But when I ran <code> authenticatedUsersReference.queryOrdered(byChild: fcmTokenKey).observe(.value)</code>, I saw that the snapshot values were ordered by the fcmTokens. <code>authenticatedUsersReference</code> points to <code>Database.database().reference().child(&quot;people/authenticated&quot;)</code>. I have also updated my rules to do indexing on the server side. As far as I can tell the concept should remain the same even if the depth changes, so what am I missing that is causing my query to return <code>nil</code>?</p>
  <pre><code>&quot;people&quot;: {
        &quot;users&quot;: {
          &quot;authenticated&quot;: {
            &quot;$userName&quot;: {
              &quot;.indexOn&quot;: [&quot;fcmToken&quot;]
            }
          }
        }
      }
  </code></pre>