javascript - 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
});
});
});
如上所示,我已准备好所有代码。我只是不知道如何从谷歌云功能编辑我的网页上的属性。任何帮助将不胜感激。
解决方案
推荐阅读
- javascript - 无法在 Meteor React 中设置未定义的属性 fullcalendar
- java - 如何使用我的 Apple Developer ID 签署 .jar 文件
- python - Django 应用程序生命周期
- python - 函数返回的数组在调用之间改变了大小
- java - new SimpleDateFormat("hh:mm a", Locale.getDefault()).parse("04:30 PM") giving Unparseable exception
- php - Algolia 过滤器不适用于对象数组
- python - 根据 dict 选择 Pandas 数据框的行
- python - csv字典在多次循环时不会重置到开头
- proxy - 邮递员 - 本地请求
- gitlab - 编辑,删除 GitLab 中存在的更改