首页 > 解决方案 > Google Cloud Functions - 编辑网页上的特定数据

问题描述

我最近开始使用 Firebase 来托管我的网站。而且我想显示一些统计信息,这些统计信息是在用户加载页面时使用 Google Cloud Functions 从数据库调用中获取的。

但是,我不确定如何将这些数据插入到我网站上的标签中。

    <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

        });
    });
});

如上所示,我已准备好所有代码。我只是不知道如何从谷歌云功能编辑我的网页上的属性。任何帮助将不胜感激。

标签: javascriptfirebasegoogle-cloud-firestoregoogle-cloud-functions

解决方案


推荐阅读