title: Firebase cannot retrieve data from database "db.collection is not a function"
body: <p>Cannot get anything from the firebase database. It is showing an error of:</p>
  
  <p><code>Uncaught TypeError: db.collection is not a function</code></p>
  
  <p>I have the script setup here as shown:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var config = {
    apiKey: "*****",
    authDomain: "*****",
    databaseURL: "*****",
    projectId: "*****",
    storageBucket: "*****",
    messagingSenderId: "*****"
  };
  firebase.initializeApp(config);
  const db = firebase.database();
  
  const firstName = document.querySelector('#firstName').value;
  const mainButton = document.querySelector('#mainButton');
  
  mainButton.addEventListener('click', () =&gt; {
    db.collection("users").doc().set({
        first: firstName,
    })
    .then(function() {
        console.log("Document successfully written!");
    })
    .catch(function(error) {
        console.error("Error writing document: ", error);
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input id="firstName" type="text" name="first-name" required&gt;
  &lt;button id="mainButton" type="button"&gt;Submit&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>What am I missing here?</p>