firebase.database.ref is not a function error

database() is a method so change it to the following:

 var reference =  firebase.database().ref();

Also better not to have same variable and method name.


I also get a database function not found issue with latest firebase library. After researching what I found is, It is due to Javascript I am importing for the database:

Previously I was using below script, Which was not working:

<script src="https://www.gstatic.com/firebasejs/7.16.0/firebase-app.js"></script>

After removing -app from the script URL, it start working:

<script src="https://www.gstatic.com/firebasejs/7.16.0/firebase.js"></script>

Hope this will be helpful for others.