I've recently gotten into using Firebase to host my website. And I'd like to display some stats which are fetched from a database call using Google Cloud Functions whenever the page is loaded by a user.
However, I'm unsure how I can insert this data into a tag on my website.
<div class="stats">
<div class="usersCard">
<h4 id=users>Users</h4>
<h1 id="usersVal">INSERTSTATSHERE</h1>
</div>
<div class="serversCard">
<h4 id=Servers>Servers</h4>
<h1 id="serversVal">INSERTSTATSHERE</h1>
</div>
<div class="infectionsCard">
<h4 id=infections>Infections</h4>
<h1 id="infectionsVal">INSERTSTATSHERE</h1>
</div>
const functions = require('firebase-functions');
exports.bigben = functions.https.onRequest((req, res) => {
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&ssl=false";
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("discord_pandemic");
dbo.collection("ArrayStats").find().toArray(function(err, result) {
if (err) throw err;
console.log(result)
const totalInfections = result[0].total_infections
const totalUsers = result[0].total_users
const totalCommands = result[0].total_commands
const totalLiveInfections = result[0].total_live_infections
const totalLiveInfectedChannels = result[0].total_live_infected_channels
});
});
});
As seen above, I have all the code ready. I just do not know how to edit an attribute on my webpage from a Google Cloud Function. Any help would be very appreciated.
tag on `pageload` using exports.app = functions.https.onRequest(app); But I can't seem to figure out how I can edit specific elements of a web page when using firebase. I usually use ```document.getElementById("lol").innerHTML = "lolsss")``` to edit specific elements. But I get a `document is undefined` error.
– deeform Aug 12 '21 at 21:33