在 Firestore 中删除包含所有子集合和嵌套子集合的文档

编程入门 行业动态 更新时间:2024-10-09 05:21:43
本文介绍了在 Firestore 中删除包含所有子集合和嵌套子集合的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何删除包含所有集合和嵌套子集合的文档?(在函数环境中)

How can you delete a Document with all it's collections and nested subcollections? (inside the functions environment)

在 RTDB 中,您可以 ref.child('../someNode).setValue(null) 并完成所需的行为.

In the RTDB you can ref.child('../someNode).setValue(null) and that completes the desired behavior.

我可以想到两种实现所需删除行为的方法,这两种方法都有非常可怕的缺点.

I can think of two ways you could achieve the desired delete behavior, both with tremendously ghastly drawbacks.

  • 创建一个超级"函数,它将抓取每个文档并批量删除它们.此函数会很复杂,不易更改,并且可能需要很长时间的执行时间.

  • Create a 'Super' function that will spider every document and delete them in a batch. This function would be complicated, brittle to changes, and might take a lengthy execution time.

    为每个文档类型添加onDelete"触发器,并使其删除任何直接子集合.您将对根文档调用 delete ,并且删除调用将沿树"向下传播.由于函数执行的巨大负载,这是缓慢的、可扩展的并且代价高昂.

    Add 'onDelete' triggers for each Document type, and make it delete any direct subcollections. You'll call delete on the root document, and the deletion calls will propagate down the 'tree'. This is sluggish, scales atrociously and is costly due to the colossal load of function executions.

    想象一下,您必须删除一个GROUP"及其所有子项.#1 会非常混乱,#2 会很贵(每个文档调用 1 个函数)

    Imagine you would have to delete a 'GROUP' and all it's children. It would be deeply chaotic with #1 and pricey with #2 (1 function call per doc)

    groups > GROUP > projects > PROJECT > files > FILE > assets > ASSET > urls > URL > members > MEMBER > questions > QUESTION > answers > ANSWER > replies > REPLY > comments > COMMENT > resources > RESOURCE > submissions > SUBMISSION > requests > REQUEST

    是否有更好/更受欢迎/更干净的方法来删除文档及其所有嵌套的子集合?

    Is there a superior/favored/cleaner way to delete a document and all it's nested subcollections?

    考虑到您可以从控制台执行此操作,这应该是可能的.

    It ought to be possible considering you can do it from the console.

    推荐答案

    根据 firebase 文档:firebase.google/docs/firestore/solutions/delete-collections删除带有嵌套子集合的集合可能会在服务器端使用 node-JS 轻松整洁地完成.

    according to firebase documentation: firebase.google/docs/firestore/solutions/delete-collections Deleting collection with nested subcollections might be done easy and neat with node-JS on the server side.

    const client = require('firebase-tools'); await client.firestore .delete(collectionPath, { project: process.env.GCLOUD_PROJECT, recursive: true, yes: true });
  • 更多推荐

    在 Firestore 中删除包含所有子集合和嵌套子集合的文档

    本文发布于:2023-11-30 07:47:15,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1649230.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:嵌套   文档   Firestore

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!