【问题标题】:Delete path and its recursive child path in firebase cloud function在firebase云功能中删除路径及其递归子路径
【发布时间】:2020-12-21 06:34:20
【问题描述】:

我想从 firestore 中删除一个文档以及该文档内的所有集合。为此,我使用以节点 8 作为引擎的云功能,它实际上已部署。但有些事情没有按预期工作。

这是我的路线 / postsCollection / user / user_posts_collection / 大文件

所以我想删除用户文档以及该文档中包含的所有内容 => user_posts_collection 及其文档

Node.js,云函数

exports.deleteUserPostsDocument = functions
    .runWith({
        timeoutSeconds: 540,
        memory: '2GB'
    })
    .https.onCall(async(data, context) => {

        const path = data.path;

        await firebase_tools.firestore
            .delete(path, {
                project: process.env.GCLOUD_PROJECT,
                recursive: true,
                yes: true,
                token: functions.config().fb.token
            });

        return {
            path: path
        };
    });

Kotlin,调用函数

val path = "/posts/user"
val data = hashMapOf("path" to path)

var success = false

functions
    .getHttpsCallable("deleteUserPostsDocument")
    .call(data)
    .continueWith {task ->
        success = task.isSuccessful
    }.await()

return success

代码与他们显示的here 完全相同,如果您只是管理员,我只是删除了要访问的代码。所以应该没有问题。

我按照 they indicated 的所有步骤进行操作,使用 firebase login、firebase login:cli 等。我可以看到该功能正在部署到我的 firebase 云功能

问题:我错过了什么?

编辑 1:这是调用云函数的屏幕截图,但没有删除任何内容。

【问题讨论】:

标签: android firebase kotlin google-cloud-firestore google-cloud-functions


【解决方案1】:

我决定看看这个sample on github 并注意到一些事情:

我有所有的包除了firebase-tools,这很奇怪,因为我在命令行中写了70次npm install -g firebase-tools作为文档表示。所以我决定自己添加它,所以现在 package.json 包含 firebase-tools 依赖项

"firebase-admin": "^9.1.1",
"firebase-functions": "^3.11.0",
"firebase-tools": "^8.9.0"

然后我在 index.js 中重写了 firebase_tools 的 require:

const firebase_tools = require('firebase-tools')

以防万一我设置了你通过执行命令行获得的令牌:firebase login:ci

在这里设置firebase functions:config:set fb.token="SET_TOKEN_HERE"

现在执行下一个命令行:firebase deploy --only functions 进行更新。

终于成功了:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    • 1970-01-01
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多