title: firebase 9 query realtime database for key
body: <p>I want to query realtime database using firebase 9, I previously used admin sdk, i have this example that works but I am having problems adjusting to version 9. I cant find any solid examples on how to use those modular methods to query. Any examples would be appreciated.</p>
  <p>version 8</p>
  <pre><code>return admin
      .database()
      .ref(&quot;Countries&quot;)
      .orderByChild(&quot;name&quot;)
      .equalTo(query)
      .once(&quot;value&quot;)
      .then((data) =&gt; {
        if (data.exists()) {
          const obj = Object.keys(data.val())[0];
          const country = data.val()[obj];
  
          return country;
        } else {
          return null;
        }
      })
      .catch((error) =&gt; {
        console.log(&quot;error finding country name&quot;, error);
        return null;
      });
  </code></pre>
  <p>what I have tried</p>
  <pre><code>const { getDatabase, child, get, ref ,orderByChild,equalTo} = require(&quot;firebase/database&quot;);
  
      const toFind = &quot;USA&quot;
  
      const dbRef = ref(getDatabase());
      const query = await get(child(dbRef, `countries`));
      //orderByChild
  
      //equalTo
  </code></pre>
  <p>UPDATED SOLUTION:</p>
  <pre><code> const dbRef = ref(db, &quot;/countries&quot;);
  
      const queryConstraints = [orderByChild(&quot;name&quot;), equalTo(name)];
  
      const country = await get(query(dbRef, ...queryConstraints));
  
      if (country.exists()) {
        console.log(&quot;found by name&quot;, country.val());
      } else {
        console.log(&quot;No data available&quot;);
        return null;
      }
    } catch (error) {
      console.log(&quot;====================================&quot;);
      console.log(&quot;error getting country&quot;, error);
      console.log(&quot;====================================&quot;);
    }
  </code></pre>