0

在此之后:https ://medium.com/@nedavniat/how-to-perform-and-schedule-firestore-backups-with-google-cloud-platform-and-nodejs-be44bbcd64ae

代码是:

const functions = require('firebase-functions'); // is installed automatically when you init the project
const { auth } = require('google-auth-library'); // is used to authenticate your request

async function exportDB () {
    const admin = await auth.getClient({
        scopes: [                               // scopes required to make a request
            'https://www.googleapis.com/auth/datastore',
            'https://www.googleapis.com/auth/cloud-platform'
        ]
    });
    const projectId = await auth.getProjectId();
    const url = `https://firestore.googleapis.com/v1beta1/projects/${projectId}/databases/(default):exportDocuments`;
    return admin.request({
        url,
        method: 'post',
        data: {
            outputUriPrefix: 'gs://name-of-the-bucket-you-created-for-backups'
        }
    });
}

常量备份 = functions.pubsub.topic('YOUR_TOPIC_NAME_HERE').onPublish(exportDB); module.exports = { 备份 };

当我通过以下方式进行部署时:

gcloud functions deploy backup --runtime nodejs8 --trigger-topic YOUR_TOPIC_NAME_HERE

我得到错误:

错误: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code。错误消息:无法加载文件 index.js 中的代码。您的代码中是否存在语法错误?

详细的堆栈跟踪:TypeError:无法读取未定义的属性“用户”

这是 google-auth-library 的东西吗?

4

1 回答 1

0

我假设您正在尝试部署由 HTTP 请求触发的 GCF 功能,我建议您检查此链接 [1] 似乎是相同的用例,并且可以帮助您在 GCF 上将 Google Cloud Datastore 与 node.js 一起使用

[1]如何在 Google Cloud Function 上使用 Node.js 按名称返回整个 Datastore 表

于 2019-09-06T20:36:00.800 回答